From 285eb56cf5a02ee778880b8e1b7bb2e8118a5a88 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 18 Feb 2024 22:39:08 -0500 Subject: [PATCH 001/258] 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 002/258] 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 003/258] 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 004/258] 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 005/258] 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 006/258] 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 007/258] 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 008/258] 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 009/258] 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 010/258] 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 011/258] 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 012/258] 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 013/258] 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 014/258] 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 015/258] 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 016/258] 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 017/258] 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 018/258] 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 019/258] 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 020/258] 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 021/258] 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 022/258] 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 023/258] 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 024/258] 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 025/258] 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 026/258] 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 027/258] 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 028/258] 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 029/258] 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 030/258] 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 031/258] 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 032/258] 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 033/258] 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 034/258] 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 035/258] 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 036/258] 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 037/258] 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 038/258] 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 039/258] 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 040/258] 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 041/258] 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 042/258] 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 043/258] 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 044/258] 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 045/258] 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 046/258] 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 047/258] 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 048/258] 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 049/258] 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 050/258] 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 051/258] 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 052/258] 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 053/258] 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 054/258] 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 055/258] 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 056/258] 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 057/258] 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 058/258] 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 059/258] 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 060/258] 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 061/258] 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 062/258] 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 063/258] 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 064/258] 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 065/258] 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 066/258] 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 067/258] 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 068/258] 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 069/258] 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 070/258] 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 071/258] 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 072/258] 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 073/258] 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 074/258] 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 075/258] 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 076/258] 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 077/258] 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 078/258] 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 079/258] 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 080/258] 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 081/258] 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 082/258] 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 083/258] 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 084/258] 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 085/258] 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 086/258] 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 087/258] 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 088/258] 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 089/258] 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 090/258] 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 091/258] 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 092/258] 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 093/258] 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 094/258] 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 095/258] 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 096/258] 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 097/258] 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 098/258] 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 099/258] 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 100/258] 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 101/258] 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 102/258] 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 103/258] 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 104/258] 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 105/258] 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 106/258] 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 107/258] 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 108/258] 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 109/258] 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 110/258] 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 111/258] 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 112/258] 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 113/258] 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 114/258] 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 136/258] 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 137/258] 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 138/258] 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 139/258] 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 140/258] 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 141/258] 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 142/258] 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 143/258] 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 144/258] 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, - "mangled name{}", - mangled - )?; + writeln!(out, "mangled name{mangled}")?; } 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 name{}", - mangled - )?; + writeln!(out, "mangled name{mangled}")?; } 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 145/258] 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 146/258] 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 147/258] 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 148/258] 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 149/258] 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 150/258] 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 151/258] 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 152/258] 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 153/258] 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 154/258] 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 155/258] 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 156/258] 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 157/258] 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 158/258] 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 159/258] 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 160/258] 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 161/258] 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 162/258] 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 163/258] 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 164/258] 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 165/258] 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 166/258] 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 167/258] 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 168/258] 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 169/258] 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 170/258] 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 171/258] 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 172/258] 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 173/258] 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 174/258] 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 175/258] 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 176/258] 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 177/258] 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 178/258] 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 179/258] 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 180/258] 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 181/258] 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 182/258] 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 183/258] 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 184/258] 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 185/258] 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 186/258] 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 187/258] 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 188/258] 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 189/258] 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 190/258] 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 191/258] 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 192/258] 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 193/258] 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 194/258] 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 195/258] 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 196/258] 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 197/258] 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 198/258] 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 199/258] 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 200/258] 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 201/258] 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 202/258] 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 203/258] 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 204/258] 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 205/258] 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 206/258] 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 207/258] 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 208/258] 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 209/258] 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 210/258] 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 211/258] 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 212/258] 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 213/258] 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 214/258] 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 215/258] 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 216/258] 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 217/258] 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 218/258] 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 219/258] 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 220/258] 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 221/258] 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 222/258] 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 223/258] 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 224/258] 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 225/258] 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 226/258] 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 227/258] 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 228/258] 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 229/258] 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 230/258] 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 231/258] 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 232/258] 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 233/258] 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 234/258] 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 235/258] 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 236/258] 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 237/258] 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 238/258] 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 239/258] 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 240/258] 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 241/258] 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 242/258] 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 243/258] 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 244/258] 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 245/258] 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 246/258] 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 247/258] 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 248/258] 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 249/258] 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 250/258] 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 251/258] 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 252/258] 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 253/258] 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#" >];"#)?; + 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 254/258] 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 255/258] 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 256/258] 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 257/258] 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 258/258] 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(),

(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 115/258] 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 116/258] 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 117/258] 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 118/258] 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 119/258] 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 120/258] 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 121/258] 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 122/258] 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 123/258] 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 124/258] 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 125/258] 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 126/258] 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 127/258] 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 128/258] 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 129/258] 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 130/258] 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 131/258] 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 132/258] 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 133/258] 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 134/258] 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 135/258] 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