summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes2
-rw-r--r--.gitignore6
-rw-r--r--CONTRIBUTING.md114
-rw-r--r--Cargo.lock15
-rw-r--r--Cargo.toml4
-rw-r--r--README.md2
-rwxr-xr-xbindgen-integration/src/lib.rs3
-rw-r--r--book/src/SUMMARY.md1
-rw-r--r--book/src/cpp.md74
-rw-r--r--book/src/faq.md66
-rw-r--r--book/src/nocopy.md10
-rw-r--r--csmith-fuzzing/README.md65
-rw-r--r--csmith-fuzzing/csmith.h15
-rwxr-xr-xcsmith-fuzzing/driver.py284
-rwxr-xr-xcsmith-fuzzing/predicate.py254
-rw-r--r--src/codegen/helpers.rs10
-rw-r--r--src/codegen/impl_debug.rs (renamed from src/codegen/derive_debug.rs)17
-rw-r--r--src/codegen/impl_partialeq.rs125
-rw-r--r--src/codegen/mod.rs511
-rw-r--r--src/codegen/struct_layout.rs13
-rw-r--r--src/features.rs14
-rw-r--r--src/ir/analysis/derive_copy.rs23
-rw-r--r--src/ir/analysis/derive_debug.rs16
-rw-r--r--src/ir/analysis/derive_default.rs20
-rw-r--r--src/ir/analysis/derive_hash.rs40
-rw-r--r--src/ir/analysis/derive_partial_eq.rs369
-rw-r--r--src/ir/analysis/derive_partial_eq_or_partial_ord.rs424
-rw-r--r--src/ir/analysis/has_destructor.rs13
-rw-r--r--src/ir/analysis/has_float.rs17
-rw-r--r--src/ir/analysis/has_type_param_in_array.rs13
-rw-r--r--src/ir/analysis/has_vtable.rs155
-rw-r--r--src/ir/analysis/mod.rs36
-rw-r--r--src/ir/analysis/sizedness.rs360
-rw-r--r--src/ir/analysis/template_params.rs9
-rw-r--r--src/ir/comp.rs357
-rw-r--r--src/ir/context.rs687
-rw-r--r--src/ir/derive.rs144
-rw-r--r--src/ir/enum_ty.rs20
-rw-r--r--src/ir/function.rs157
-rw-r--r--src/ir/item.rs217
-rw-r--r--src/ir/layout.rs43
-rw-r--r--src/ir/module.rs4
-rw-r--r--src/ir/objc.rs14
-rw-r--r--src/ir/template.rs35
-rw-r--r--src/ir/traversal.rs4
-rw-r--r--src/ir/ty.rs109
-rw-r--r--src/ir/var.rs20
-rw-r--r--src/lib.rs470
-rw-r--r--src/options.rs99
-rw-r--r--src/parse.rs14
-rw-r--r--src/regex_set.rs15
-rw-r--r--tests/expectations/struct_with_anon_struct_array_float.rs1
-rw-r--r--tests/expectations/tests/16-byte-alignment.rs370
-rw-r--r--tests/expectations/tests/16-byte-alignment_1_0.rs389
-rw-r--r--tests/expectations/tests/accessors.rs350
-rw-r--r--tests/expectations/tests/annotation_hide.rs14
-rw-r--r--tests/expectations/tests/anon_enum.rs58
-rw-r--r--tests/expectations/tests/anon_enum_trait.rs42
-rw-r--r--tests/expectations/tests/anon_enum_whitelist.rs5
-rw-r--r--tests/expectations/tests/anon_struct_in_union.rs106
-rw-r--r--tests/expectations/tests/anon_struct_in_union_1_0.rs137
-rw-r--r--tests/expectations/tests/anon_union.rs52
-rw-r--r--tests/expectations/tests/anon_union_1_0.rs94
-rw-r--r--tests/expectations/tests/anonymous-template-types.rs12
-rw-r--r--tests/expectations/tests/arg_keyword.rs2
-rw-r--r--tests/expectations/tests/array-of-zero-sized-types.rs56
-rw-r--r--tests/expectations/tests/bad-namespace-parenthood-inheritance.rs4
-rw-r--r--tests/expectations/tests/base-to-derived.rs19
-rw-r--r--tests/expectations/tests/bitfield-32bit-overflow.rs208
-rw-r--r--tests/expectations/tests/bitfield-enum-basic.rs115
-rw-r--r--tests/expectations/tests/bitfield-large.rs24
-rw-r--r--tests/expectations/tests/bitfield-method-same-name.rs22
-rw-r--r--tests/expectations/tests/bitfield_align.rs204
-rw-r--r--tests/expectations/tests/bitfield_align_2.rs19
-rw-r--r--tests/expectations/tests/bitfield_large_overflow.rs28
-rw-r--r--tests/expectations/tests/bitfield_method_mangling.rs19
-rw-r--r--tests/expectations/tests/c-empty-layout.rs22
-rw-r--r--tests/expectations/tests/canonical_path_without_namespacing.rs21
-rw-r--r--tests/expectations/tests/char.rs199
-rw-r--r--tests/expectations/tests/class.rs465
-rw-r--r--tests/expectations/tests/class_1_0.rs498
-rw-r--r--tests/expectations/tests/class_nested.rs66
-rw-r--r--tests/expectations/tests/class_no_members.rs76
-rw-r--r--tests/expectations/tests/class_static.rs28
-rw-r--r--tests/expectations/tests/class_static_const.rs19
-rw-r--r--tests/expectations/tests/class_use_as.rs14
-rw-r--r--tests/expectations/tests/class_with_dtor.rs11
-rw-r--r--tests/expectations/tests/class_with_inner_struct.rs512
-rw-r--r--tests/expectations/tests/class_with_inner_struct_1_0.rs523
-rw-r--r--tests/expectations/tests/class_with_typedef.rs121
-rw-r--r--tests/expectations/tests/comment-indent.rs112
-rw-r--r--tests/expectations/tests/complex.rs144
-rw-r--r--tests/expectations/tests/complex_global.rs6
-rw-r--r--tests/expectations/tests/const_enum_unnamed.rs28
-rw-r--r--tests/expectations/tests/const_tparam.rs6
-rw-r--r--tests/expectations/tests/constify-all-enums.rs7
-rw-r--r--tests/expectations/tests/constify-enum.rs3
-rw-r--r--tests/expectations/tests/constify-module-enums-basic.rs7
-rw-r--r--tests/expectations/tests/constify-module-enums-namespace.rs38
-rw-r--r--tests/expectations/tests/constify-module-enums-shadow-name.rs38
-rw-r--r--tests/expectations/tests/constify-module-enums-simple-alias.rs7
-rw-r--r--tests/expectations/tests/constify-module-enums-simple-nonamespace.rs53
-rw-r--r--tests/expectations/tests/constify-module-enums-types.rs277
-rw-r--r--tests/expectations/tests/constructor-tp.rs21
-rw-r--r--tests/expectations/tests/constructors.rs47
-rw-r--r--tests/expectations/tests/contains-vs-inherits-zero-sized.rs97
-rw-r--r--tests/expectations/tests/convert-cpp-comment-to-rust.rs68
-rw-r--r--tests/expectations/tests/convert-floats.rs113
-rw-r--r--tests/expectations/tests/cpp-empty-layout.rs19
-rw-r--r--tests/expectations/tests/crtp.rs78
-rw-r--r--tests/expectations/tests/decl_extern_int_twice.rs2
-rw-r--r--tests/expectations/tests/decl_ptr_to_array.rs2
-rw-r--r--tests/expectations/tests/default-template-parameter.rs2
-rw-r--r--tests/expectations/tests/derive-bitfield-method-same-name.rs131
-rw-r--r--tests/expectations/tests/derive-clone.rs41
-rw-r--r--tests/expectations/tests/derive-clone_1_0.rs47
-rw-r--r--tests/expectations/tests/derive-debug-bitfield.rs19
-rw-r--r--tests/expectations/tests/derive-debug-function-pointer.rs72
-rw-r--r--tests/expectations/tests/derive-debug-opaque-template-instantiation.rs35
-rw-r--r--tests/expectations/tests/derive-debug-opaque.rs55
-rw-r--r--tests/expectations/tests/derive-fn-ptr.rs142
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs16
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-float-array.rs9
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs121
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-pointer.rs30
-rw-r--r--tests/expectations/tests/derive-hash-template-def-float.rs4
-rw-r--r--tests/expectations/tests/derive-hash-template-inst-float.rs48
-rw-r--r--tests/expectations/tests/derive-partialeq-anonfield.rs47
-rw-r--r--tests/expectations/tests/derive-partialeq-base.rs72
-rw-r--r--tests/expectations/tests/derive-partialeq-bitfield.rs125
-rw-r--r--tests/expectations/tests/derive-partialeq-core.rs45
-rw-r--r--tests/expectations/tests/derive-partialeq-pointer.rs109
-rw-r--r--tests/expectations/tests/derive-partialeq-union.rs53
-rw-r--r--tests/expectations/tests/derive-partialeq-union_1_0.rs105
-rw-r--r--tests/expectations/tests/do-not-derive-copy.rs37
-rw-r--r--tests/expectations/tests/doggo-or-null.rs76
-rw-r--r--tests/expectations/tests/duplicated-namespaces-definitions.rs87
-rw-r--r--tests/expectations/tests/elaborated.rs2
-rw-r--r--tests/expectations/tests/enum.rs10
-rw-r--r--tests/expectations/tests/enum_alias.rs4
-rw-r--r--tests/expectations/tests/enum_and_vtable_mangling.rs39
-rw-r--r--tests/expectations/tests/enum_dupe.rs4
-rw-r--r--tests/expectations/tests/enum_explicit_type.rs27
-rw-r--r--tests/expectations/tests/enum_in_template_with_typedef.rs4
-rw-r--r--tests/expectations/tests/enum_negative.rs5
-rw-r--r--tests/expectations/tests/enum_packed.rs15
-rw-r--r--tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs7
-rw-r--r--tests/expectations/tests/extern.rs7
-rw-r--r--tests/expectations/tests/float128.rs3
-rw-r--r--tests/expectations/tests/forward-declaration-autoptr.rs17
-rw-r--r--tests/expectations/tests/forward-enum-decl.rs5
-rw-r--r--tests/expectations/tests/forward-inherit-struct-with-fields.rs12
-rw-r--r--tests/expectations/tests/forward-inherit-struct.rs4
-rw-r--r--tests/expectations/tests/forward_declared_complex_types.rs58
-rw-r--r--tests/expectations/tests/forward_declared_complex_types_1_0.rs56
-rw-r--r--tests/expectations/tests/forward_declared_struct.rs56
-rw-r--r--tests/expectations/tests/func_proto.rs7
-rw-r--r--tests/expectations/tests/func_ptr.rs11
-rw-r--r--tests/expectations/tests/func_ptr_in_struct.rs48
-rw-r--r--tests/expectations/tests/gen-constructors-neg.rs19
-rw-r--r--tests/expectations/tests/gen-constructors.rs9
-rw-r--r--tests/expectations/tests/gen-destructors-neg.rs29
-rw-r--r--tests/expectations/tests/gen-destructors.rs35
-rw-r--r--tests/expectations/tests/generate-inline.rs27
-rw-r--r--tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs208
-rw-r--r--tests/expectations/tests/inherit-namespaced.rs4
-rw-r--r--tests/expectations/tests/inherit_named.rs6
-rw-r--r--tests/expectations/tests/inherit_typedef.rs38
-rw-r--r--tests/expectations/tests/inline-function.rs3
-rw-r--r--tests/expectations/tests/inline_namespace.rs34
-rw-r--r--tests/expectations/tests/inline_namespace_conservative.rs34
-rw-r--r--tests/expectations/tests/inline_namespace_no_ns_enabled.rs16
-rw-r--r--tests/expectations/tests/inner_const.rs38
-rw-r--r--tests/expectations/tests/inner_template_self.rs61
-rw-r--r--tests/expectations/tests/int128_t.rs3
-rw-r--r--tests/expectations/tests/issue-1025-unknown-enum-repr.rs12
-rw-r--r--tests/expectations/tests/issue-1034.rs30
-rw-r--r--tests/expectations/tests/issue-1040.rs7
-rw-r--r--tests/expectations/tests/issue-358.rs8
-rw-r--r--tests/expectations/tests/issue-372.rs114
-rw-r--r--tests/expectations/tests/issue-410.rs11
-rw-r--r--tests/expectations/tests/issue-446.rs8
-rw-r--r--tests/expectations/tests/issue-447.rs16
-rw-r--r--tests/expectations/tests/issue-493.rs78
-rw-r--r--tests/expectations/tests/issue-493_1_0.rs74
-rw-r--r--tests/expectations/tests/issue-544-stylo-creduce-2.rs4
-rw-r--r--tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs51
-rw-r--r--tests/expectations/tests/issue-573-layout-test-failures.rs49
-rw-r--r--tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs51
-rw-r--r--tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs87
-rw-r--r--tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs12
-rw-r--r--tests/expectations/tests/issue-639-typedef-anon-field.rs121
-rw-r--r--tests/expectations/tests/issue-643-inner-struct.rs107
-rw-r--r--tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs9
-rw-r--r--tests/expectations/tests/issue-648-derive-debug-with-padding.rs24
-rw-r--r--tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs18
-rw-r--r--tests/expectations/tests/issue-662-part-2.rs15
-rw-r--r--tests/expectations/tests/issue-674-1.rs36
-rw-r--r--tests/expectations/tests/issue-674-2.rs82
-rw-r--r--tests/expectations/tests/issue-674-3.rs63
-rw-r--r--tests/expectations/tests/issue-691-template-parameter-virtual.rs64
-rw-r--r--tests/expectations/tests/issue-739-pointer-wide-bitfield.rs19
-rw-r--r--tests/expectations/tests/issue-801-opaque-sloppiness.rs49
-rw-r--r--tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs116
-rw-r--r--tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs19
-rw-r--r--tests/expectations/tests/issue-833-1.rs5
-rw-r--r--tests/expectations/tests/issue-833.rs5
-rw-r--r--tests/expectations/tests/issue-834.rs19
-rw-r--r--tests/expectations/tests/issue-888-enum-var-decl-jump.rs23
-rw-r--r--tests/expectations/tests/issue_311.rs42
-rw-r--r--tests/expectations/tests/jsval_layout_opaque.rs47
-rw-r--r--tests/expectations/tests/jsval_layout_opaque_1_0.rs14
-rw-r--r--tests/expectations/tests/keywords.rs98
-rw-r--r--tests/expectations/tests/layout.rs23
-rw-r--r--tests/expectations/tests/layout_align.rs25
-rw-r--r--tests/expectations/tests/layout_arp.rs222
-rw-r--r--tests/expectations/tests/layout_array.rs380
-rw-r--r--tests/expectations/tests/layout_array_too_long.rs323
-rw-r--r--tests/expectations/tests/layout_cmdline_token.rs28
-rw-r--r--tests/expectations/tests/layout_eth_conf.rs226
-rw-r--r--tests/expectations/tests/layout_eth_conf_1_0.rs74
-rw-r--r--tests/expectations/tests/layout_kni_mbuf.rs226
-rw-r--r--tests/expectations/tests/layout_large_align_field.rs667
-rw-r--r--tests/expectations/tests/layout_mbuf.rs181
-rw-r--r--tests/expectations/tests/layout_mbuf_1_0.rs92
-rw-r--r--tests/expectations/tests/libclang-3.8/auto.rs11
-rw-r--r--tests/expectations/tests/libclang-3.8/call-conv-field.rs9
-rw-r--r--tests/expectations/tests/libclang-3.8/const_bool.rs13
-rw-r--r--tests/expectations/tests/libclang-3.8/constant-evaluate.rs14
-rw-r--r--tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs11
-rw-r--r--tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs7
-rw-r--r--tests/expectations/tests/libclang-3.9/auto.rs9
-rw-r--r--tests/expectations/tests/libclang-3.9/call-conv-field.rs9
-rw-r--r--tests/expectations/tests/libclang-3.9/const_bool.rs7
-rw-r--r--tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs9
-rw-r--r--tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs7
-rw-r--r--tests/expectations/tests/libclang-4/auto.rs21
-rw-r--r--tests/expectations/tests/libclang-4/call-conv-field.rs63
-rw-r--r--tests/expectations/tests/libclang-4/const_bool.rs19
-rw-r--r--tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs21
-rw-r--r--tests/expectations/tests/libclang-4/type_alias_template_specialized.rs18
-rw-r--r--tests/expectations/tests/mangling-ios.rs1
-rw-r--r--tests/expectations/tests/mangling-linux32.rs21
-rw-r--r--tests/expectations/tests/mangling-linux64.rs21
-rw-r--r--tests/expectations/tests/mangling-macos.rs22
-rw-r--r--tests/expectations/tests/mangling-win32.rs8
-rw-r--r--tests/expectations/tests/mangling-win64.rs21
-rw-r--r--tests/expectations/tests/method-mangling.rs25
-rw-r--r--tests/expectations/tests/module-whitelisted.rs19
-rw-r--r--tests/expectations/tests/msvc-no-usr.rs29
-rw-r--r--tests/expectations/tests/multiple-inherit-empty-correct-layout.rs57
-rw-r--r--tests/expectations/tests/mutable.rs120
-rw-r--r--tests/expectations/tests/namespace.rs21
-rw-r--r--tests/expectations/tests/nested.rs122
-rw-r--r--tests/expectations/tests/nested_vtable.rs74
-rw-r--r--tests/expectations/tests/nested_within_namespace.rs102
-rw-r--r--tests/expectations/tests/no-comments.rs29
-rw-r--r--tests/expectations/tests/no-hash-opaque.rs24
-rw-r--r--tests/expectations/tests/no-hash-whitelisted.rs34
-rw-r--r--tests/expectations/tests/no-partialeq-opaque.rs24
-rw-r--r--tests/expectations/tests/no-partialeq-whitelisted.rs34
-rw-r--r--tests/expectations/tests/no-recursive-whitelisting.rs33
-rw-r--r--tests/expectations/tests/no-std.rs64
-rw-r--r--tests/expectations/tests/no_copy_opaque.rs24
-rw-r--r--tests/expectations/tests/no_copy_whitelisted.rs34
-rw-r--r--tests/expectations/tests/non-type-params.rs64
-rw-r--r--tests/expectations/tests/nsStyleAutoArray.rs12
-rw-r--r--tests/expectations/tests/objc_category.rs11
-rw-r--r--tests/expectations/tests/objc_class.rs9
-rw-r--r--tests/expectations/tests/objc_class_method.rs11
-rw-r--r--tests/expectations/tests/objc_interface.rs11
-rw-r--r--tests/expectations/tests/objc_interface_type.rs47
-rw-r--r--tests/expectations/tests/objc_method.rs11
-rw-r--r--tests/expectations/tests/objc_property_fnptr.rs5
-rw-r--r--tests/expectations/tests/objc_protocol.rs11
-rw-r--r--tests/expectations/tests/objc_sel_and_id.rs7
-rw-r--r--tests/expectations/tests/objc_whitelist.rs9
-rw-r--r--tests/expectations/tests/only_bitfields.rs22
-rw-r--r--tests/expectations/tests/opaque-template-inst-member-2.rs18
-rw-r--r--tests/expectations/tests/opaque-template-inst-member.rs102
-rw-r--r--tests/expectations/tests/opaque-template-instantiation-namespaced.rs39
-rw-r--r--tests/expectations/tests/opaque-template-instantiation.rs25
-rw-r--r--tests/expectations/tests/opaque-tracing.rs21
-rw-r--r--tests/expectations/tests/opaque_in_struct.rs14
-rw-r--r--tests/expectations/tests/opaque_pointer.rs18
-rw-r--r--tests/expectations/tests/overflowed_enum.rs5
-rw-r--r--tests/expectations/tests/overloading.rs11
-rw-r--r--tests/expectations/tests/prepend-enum-constified-variant.rs4
-rw-r--r--tests/expectations/tests/private.rs147
-rw-r--r--tests/expectations/tests/public-dtor.rs20
-rw-r--r--tests/expectations/tests/ref_argument_array.rs32
-rw-r--r--tests/expectations/tests/reparented_replacement.rs34
-rw-r--r--tests/expectations/tests/replace_use.rs7
-rw-r--r--tests/expectations/tests/replaces_double.rs12
-rw-r--r--tests/expectations/tests/same_struct_name_in_different_namespaces.rs49
-rw-r--r--tests/expectations/tests/sentry-defined-multiple-times.rs358
-rw-r--r--tests/expectations/tests/short-enums.rs12
-rw-r--r--tests/expectations/tests/size_t_template.rs29
-rw-r--r--tests/expectations/tests/struct_containing_forward_declared_struct.rs72
-rw-r--r--tests/expectations/tests/struct_typedef.rs81
-rw-r--r--tests/expectations/tests/struct_typedef_ns.rs14
-rw-r--r--tests/expectations/tests/struct_with_anon_struct.rs83
-rw-r--r--tests/expectations/tests/struct_with_anon_struct_array.rs147
-rw-r--r--tests/expectations/tests/struct_with_anon_struct_pointer.rs87
-rw-r--r--tests/expectations/tests/struct_with_anon_union.rs91
-rw-r--r--tests/expectations/tests/struct_with_anon_union_1_0.rs123
-rw-r--r--tests/expectations/tests/struct_with_anon_unnamed_struct.rs68
-rw-r--r--tests/expectations/tests/struct_with_anon_unnamed_union.rs76
-rw-r--r--tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs108
-rw-r--r--tests/expectations/tests/struct_with_bitfields.rs43
-rw-r--r--tests/expectations/tests/struct_with_derive_debug.rs144
-rw-r--r--tests/expectations/tests/struct_with_large_array.rs44
-rw-r--r--tests/expectations/tests/struct_with_nesting.rs213
-rw-r--r--tests/expectations/tests/struct_with_nesting_1_0.rs243
-rw-r--r--tests/expectations/tests/struct_with_packing.rs37
-rw-r--r--tests/expectations/tests/struct_with_struct.rs83
-rw-r--r--tests/expectations/tests/struct_with_typedef_template_arg.rs3
-rw-r--r--tests/expectations/tests/template-fun-ty.rs8
-rw-r--r--tests/expectations/tests/template-param-usage-0.rs6
-rw-r--r--tests/expectations/tests/template-param-usage-10.rs12
-rw-r--r--tests/expectations/tests/template-param-usage-12.rs12
-rw-r--r--tests/expectations/tests/template-param-usage-13.rs6
-rw-r--r--tests/expectations/tests/template-param-usage-14.rs4
-rw-r--r--tests/expectations/tests/template-param-usage-15.rs10
-rw-r--r--tests/expectations/tests/template-param-usage-2.rs12
-rw-r--r--tests/expectations/tests/template-param-usage-3.rs13
-rw-r--r--tests/expectations/tests/template-param-usage-4.rs6
-rw-r--r--tests/expectations/tests/template-param-usage-5.rs6
-rw-r--r--tests/expectations/tests/template-param-usage-7.rs6
-rw-r--r--tests/expectations/tests/template-param-usage-8.rs6
-rw-r--r--tests/expectations/tests/template-param-usage-9.rs6
-rw-r--r--tests/expectations/tests/template.rs382
-rw-r--r--tests/expectations/tests/template_alias.rs6
-rw-r--r--tests/expectations/tests/template_alias_namespace.rs6
-rw-r--r--tests/expectations/tests/template_partial_specification.rs3
-rw-r--r--tests/expectations/tests/template_typedef_transitive_param.rs6
-rw-r--r--tests/expectations/tests/test_multiple_header_calls_in_builder.rs210
-rw-r--r--tests/expectations/tests/type-referenced-by-whitelisted-function.rs34
-rw-r--r--tests/expectations/tests/type_alias_partial_template_especialization.rs6
-rw-r--r--tests/expectations/tests/typeref.rs158
-rw-r--r--tests/expectations/tests/typeref_1_0.rs189
-rw-r--r--tests/expectations/tests/underscore.rs35
-rw-r--r--tests/expectations/tests/union-in-ns.rs38
-rw-r--r--tests/expectations/tests/union-in-ns_1_0.rs67
-rw-r--r--tests/expectations/tests/union_bitfield.rs175
-rw-r--r--tests/expectations/tests/union_bitfield_1_0.rs242
-rw-r--r--tests/expectations/tests/union_dtor.rs50
-rw-r--r--tests/expectations/tests/union_dtor_1_0.rs88
-rw-r--r--tests/expectations/tests/union_fields.rs68
-rw-r--r--tests/expectations/tests/union_fields_1_0.rs105
-rw-r--r--tests/expectations/tests/union_template.rs16
-rw-r--r--tests/expectations/tests/union_template_1_0.rs42
-rw-r--r--tests/expectations/tests/union_with_anon_struct.rs87
-rw-r--r--tests/expectations/tests/union_with_anon_struct_1_0.rs123
-rw-r--r--tests/expectations/tests/union_with_anon_struct_bitfield.rs26
-rw-r--r--tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs14
-rw-r--r--tests/expectations/tests/union_with_anon_union.rs91
-rw-r--r--tests/expectations/tests/union_with_anon_union_1_0.rs123
-rw-r--r--tests/expectations/tests/union_with_anon_unnamed_struct.rs118
-rw-r--r--tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs154
-rw-r--r--tests/expectations/tests/union_with_anon_unnamed_union.rs86
-rw-r--r--tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs118
-rw-r--r--tests/expectations/tests/union_with_big_member.rs159
-rw-r--r--tests/expectations/tests/union_with_big_member_1_0.rs194
-rw-r--r--tests/expectations/tests/union_with_nesting.rs174
-rw-r--r--tests/expectations/tests/union_with_nesting_1_0.rs196
-rw-r--r--tests/expectations/tests/unknown_attr.rs44
-rw-r--r--tests/expectations/tests/use-core.rs116
-rw-r--r--tests/expectations/tests/use-core_1_0.rs152
-rw-r--r--tests/expectations/tests/using.rs6
-rw-r--r--tests/expectations/tests/var-tracing.rs57
-rw-r--r--tests/expectations/tests/variadic-method.rs23
-rw-r--r--tests/expectations/tests/vector.rs34
-rw-r--r--tests/expectations/tests/virtual_dtor.rs20
-rw-r--r--tests/expectations/tests/virtual_inheritance.rs118
-rw-r--r--tests/expectations/tests/virtual_overloaded.rs33
-rw-r--r--tests/expectations/tests/vtable_recursive_sig.rs48
-rw-r--r--tests/expectations/tests/weird_bitfields.rs49
-rw-r--r--tests/expectations/tests/what_is_going_on.rs25
-rw-r--r--tests/expectations/tests/whitelist-namespaces-basic.rs19
-rw-r--r--tests/expectations/tests/whitelist-namespaces.rs53
-rw-r--r--tests/expectations/tests/whitelist_basic.rs12
-rw-r--r--tests/expectations/tests/whitelisted-item-references-no-hash.rs52
-rw-r--r--tests/expectations/tests/whitelisted-item-references-no-partialeq.rs52
-rw-r--r--tests/expectations/tests/whitelisted_item_references_no_copy.rs52
-rw-r--r--tests/expectations/tests/win32-thiscall_1_0.rs29
-rw-r--r--tests/expectations/tests/win32-thiscall_nightly.rs43
-rw-r--r--tests/expectations/tests/zero-sized-array.rs159
-rw-r--r--tests/headers/array-of-zero-sized-types.hpp12
-rw-r--r--tests/headers/bitfield_large_overflow.hpp3
-rw-r--r--tests/headers/call-conv-field.h2
-rw-r--r--tests/headers/class.hpp18
-rw-r--r--tests/headers/class_1_0.hpp20
-rw-r--r--tests/headers/contains-vs-inherits-zero-sized.hpp21
-rw-r--r--tests/headers/derive-bitfield-method-same-name.hpp13
-rw-r--r--tests/headers/derive-clone.h5
-rw-r--r--tests/headers/derive-clone_1_0.h7
-rw-r--r--tests/headers/derive-hash-blacklisting.hpp2
-rw-r--r--tests/headers/derive-hash-struct-with-anon-struct-float.h4
-rw-r--r--tests/headers/derive-hash-struct-with-float-array.h4
-rw-r--r--tests/headers/derive-hash-struct-with-incomplete-array.h17
-rw-r--r--tests/headers/derive-hash-struct-with-pointer.h4
-rw-r--r--tests/headers/derive-hash-template-def-float.hpp4
-rw-r--r--tests/headers/derive-hash-template-inst-float.hpp8
-rw-r--r--tests/headers/derive-partialeq-anonfield.h5
-rw-r--r--tests/headers/derive-partialeq-base.hpp8
-rw-r--r--tests/headers/derive-partialeq-bitfield.hpp7
-rw-r--r--tests/headers/derive-partialeq-core.h5
-rw-r--r--tests/headers/derive-partialeq-pointer.hpp12
-rw-r--r--tests/headers/derive-partialeq-union.hpp7
-rw-r--r--tests/headers/derive-partialeq-union_1_0.hpp7
-rw-r--r--tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h3
-rw-r--r--tests/headers/inherit-from-template-instantiation-with-vtable.hpp37
-rw-r--r--tests/headers/issue-1025-unknown-enum-repr.hpp4
-rw-r--r--tests/headers/issue-1034.h4
-rw-r--r--tests/headers/issue-1040.h1
-rw-r--r--tests/headers/issue-648-derive-debug-with-padding.h2
-rw-r--r--tests/headers/layout_array.h2
-rw-r--r--tests/headers/layout_array_too_long.h2
-rw-r--r--tests/headers/no-hash-opaque.hpp5
-rw-r--r--tests/headers/no-hash-whitelisted.hpp5
-rw-r--r--tests/headers/no-partialeq-opaque.hpp5
-rw-r--r--tests/headers/no-partialeq-whitelisted.hpp5
-rw-r--r--tests/headers/no_copy_opaque.hpp5
-rw-r--r--tests/headers/no_copy_whitelisted.hpp5
-rw-r--r--tests/headers/opaque-template-inst-member.hpp8
-rw-r--r--tests/headers/sentry-defined-multiple-times.hpp85
-rw-r--r--tests/headers/underscore.hpp3
-rw-r--r--tests/headers/union_bitfield.h10
-rw-r--r--tests/headers/union_bitfield_1_0.h14
-rw-r--r--tests/headers/whitelisted-item-references-no-hash.hpp7
-rw-r--r--tests/headers/whitelisted-item-references-no-partialeq.hpp7
-rw-r--r--tests/headers/whitelisted_item_references_no_copy.hpp7
-rw-r--r--tests/headers/win32-thiscall_1_0.hpp7
-rw-r--r--tests/headers/win32-thiscall_nightly.hpp7
-rw-r--r--tests/headers/zero-sized-array.hpp45
-rw-r--r--tests/rustfmt.toml1
-rw-r--r--tests/tests.rs22
438 files changed, 18680 insertions, 9053 deletions
diff --git a/.gitattributes b/.gitattributes
index 84af5d5b..041e00f3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,3 @@
tests/stylo.hpp -diff
+tests/headers/* eol=lf
+tests/expectations/tests/* eol=lf \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index b2bfe5aa..91419086 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,9 @@ ir.png
# Output of the --dump-preprocessed-input flag.
__bindgen.*
+
+# Generated by C-Smith
+csmith-fuzzing/platform.info
+
+# Backups of test cases from C-Reduce
+**.orig
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ade50b7a..0a06709a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -19,11 +19,13 @@ out to us in a GitHub issue, or stop by
- [Testing a Single Header's Bindings Generation and Compiling its Bindings](#testing-a-single-headers-bindings-generation-and-compiling-its-bindings)
- [Authoring New Tests](#authoring-new-tests)
- [Test Expectations and `libclang` Versions](#test-expectations-and-libclang-versions)
+ - [Fuzzing `bindgen` with `csmith`](#fuzzing-bindgen-with-csmith)
- [Code Overview](#code-overview)
- [Pull Requests and Code Reviews](#pull-requests-and-code-reviews)
- [Generating Graphviz Dot Files](#generating-graphviz-dot-files)
- [Debug Logging](#debug-logging)
- [Using `creduce` to Minimize Test Cases](#using-creduce-to-minimize-test-cases)
+ - [Getting `creduce`](#getting-creduce)
- [Isolating Your Test Case](#isolating-your-test-case)
- [Writing a Predicate Script](#writing-a-predicate-script)
@@ -193,6 +195,14 @@ Where `$VERSION` is one of:
depending on which version of `libclang` you have installed.
+### Fuzzing `bindgen` with `csmith`
+
+We <3 finding hidden bugs and the people who help us find them! One way to help
+uncover hidden bugs is by running `csmith` to generate random headers to test
+`bindgen` against.
+
+See [./csmith-fuzzing/README.md](./csmith-fuzzing/README.md) for details.
+
## Code Overview
`bindgen` takes C and C++ header files as input and generates corresponding Rust
@@ -273,6 +283,7 @@ Unsure who to ask for review? Ask any of:
* `@emilio`
* `@fitzgen`
+* `@pepyakin`
More resources:
@@ -327,11 +338,25 @@ $ RUST_LOG=bindgen cargo test
## Using `creduce` to Minimize Test Cases
-If you are hacking on `bindgen` and find a test case that causes an unexpected
-panic, results in bad Rust bindings, or some other incorrectness in `bindgen`,
-then using `creduce` can help reduce the test case to a minimal one.
+If you find a test case that triggers an unexpected panic in `bindgen`, causes
+`bindgen` to emit bindings that won't compile, define structs with the wrong
+size/alignment, or results in any other kind of incorrectness, then using
+`creduce` can help reduce the test case to a minimal one that still exhibits
+that same bad behavior.
-[Follow these instructions for building and/or installing `creduce`.](https://github.com/csmith-project/creduce/blob/master/INSTALL)
+***Reduced test cases are SUPER helpful when filing bug reports!***
+
+### Getting `creduce`
+
+Often, you can install `creduce` from your OS's package manager:
+
+```
+$ sudo apt install creduce
+$ brew install creduce
+$ # Etc...
+```
+
+[Otherwise, follow these instructions for building and/or installing `creduce`.](https://github.com/csmith-project/creduce/blob/master/INSTALL)
Running `creduce` requires two things:
@@ -342,7 +367,7 @@ Running `creduce` requires two things:
With those two things in hand, running `creduce` looks like this:
- $ creduce ./predicate.sh ./isolated_test_case.h
+ $ creduce ./predicate.sh ./isolated-test-case.h
### Isolating Your Test Case
@@ -359,12 +384,9 @@ standalone test case.
### Writing a Predicate Script
-Writing a `predicate.sh` script for a `bindgen` test case is fairly
-straightforward. One potential gotcha is that `creduce` can and will attempt to
-reduce test cases into invalid C/C++ code. That might be useful for C/C++
-compilers, but we generally only care about valid C/C++ input headers.
-
-Here is a skeleton predicate script:
+Writing a `predicate.sh` script for a `bindgen` test case is straightforward. We
+already have a general purpose predicate script that you can use, you just have
+to wrap and configure it.
```bash
#!/usr/bin/env bash
@@ -374,39 +396,61 @@ Here is a skeleton predicate script:
# * we access any undefined variable.
set -eu
-# Print out Rust backtraces on panic. Useful for minimizing a particular panic.
-export RUST_BACKTRACE=1
+# Invoke the general purpose predicate script that comes in the
+# `bindgen` repository.
+#
+# You'll need to replace `--whatever-flags` with things that are specific to the
+# incorrectness you're trying to pin down. See below for details.
+path/to/rust-bindgen/csmith-fuzzing/predicate.py \
+ --whatever-flags \
+ ./isolated-test-case.h
+```
-# If the `libclang.so` you're using for `bindgen` isn't the system
-# `libclang.so`, let the linker find it.
-export LD_LIBRARY_PATH=~/path/to/your/directory/containing/libclang
+When hunting down a particular panic emanating from inside `bindgen`, you can
+invoke `predicate.py` like this:
-# Make sure that the reduced test case is valid C/C++ by compiling it. If it
-# isn't valid C/C++, this command will exit with a nonzero exit code and cause
-# the whole script to do the same.
-clang[++ --std=c++14] -c ./pre_processed_header.hpp
+```bash
+path/to/rust-bindgen/csmith-fuzzing/predicate.py \
+ --expect-bindgen-fail \
+ --bindgen-grep "thread main panicked at '<insert panic message here>'" \
+ ./isolated-test-case.h
+```
-# Run `bindgen` and `grep` for the thing your hunting down! Make sure to include
-# `2>&1` to get at stderr if you're hunting down a panic.
-~/src/rust-bindgen/target/debug/bindgen \
- ./pre_processed_header.hpp \
- [ <extra flags> ] \
- 2>&1 \
- | grep "<pattern in generated bindings or a panic string or ...>"
+Alternatively, when hunting down a bad `#[derive(Eq)]` that is causing `rustc`
+to fail to compile `bindgen`'s emitted bindings, you can invoke `predicate.py`
+like this:
+
+```bash
+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' \
+ ./isolated-test-case.h
```
-When hunting down a panic, I `grep`ed like this:
+Or, when minimizing a failing layout test in the compiled bindings, you can
+invoke `predicate.py` like this:
- ... | grep "thread main panicked at '<panic error message here>'"
+```bash
+path/to/rust-bindgen/csmith-fuzzing/predicate.py \
+ --bindings-grep MyStruct \
+ --expect-layout-tests-fail \
+ --layout-tests-grep "thread 'bindgen_test_layout_MyStruct' panicked" \
+ ./isolated-test-case.h
+```
+
+For details on all the flags that you can pass to `predicate.py`, run:
-When hunting down bad codegen for a base member, I `grep`ed like this:
+```
+$ path/to/rust-bindgen/csmith-fuzzing/predicate.py --help
+```
- ... | grep "pub _base: MyInvalidBaseTypeThatShouldntBeHere"
+And you can always write your own, arbitrary predicate script if you prefer.
+(Although, maybe we should add extra functionality to `predicate.py` -- file an
+issue if you think so!)
-That's pretty much it! I want to impress upon you that `creduce` is *really*
-helpful and has enabled me to reduce 30k lines of test case into 5 lines. And it
-works pretty quickly too. Super valuable tool to have in your belt when hacking
-on `bindgen`!
+`creduce` is *really* helpful and can cut hundreds of thousands of lines of test
+case down to 5 lines.
Happy bug hunting and test case reducing!
diff --git a/Cargo.lock b/Cargo.lock
index c1218383..ce443cc5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,10 +1,10 @@
[root]
name = "bindgen"
-version = "0.30.0"
+version = "0.31.0"
dependencies = [
"cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "clang-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clang-sys 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)",
"diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -46,11 +46,6 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "bitflags"
-version = "0.9.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "cexpr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -65,10 +60,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clang-sys"
-version = "0.19.0"
+version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -276,10 +270,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
-"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d"
"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
-"checksum clang-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "611ec2e3a7623afd8a8c0d027887b6b55759d894abbf5fe11b9dc11b50d5b49a"
+"checksum clang-sys 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5955eab05fa8e6ff2b353753dc73a0608daa36e472a21c69f2eb51f43f593544"
"checksum clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b8f69e518f967224e628896b54e41ff6acfb4dcfefc5076325c36525dac900f"
"checksum diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0a515461b6c8c08419850ced27bc29e86166dcdcde8fbe76f8b1f0589bb49472"
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
diff --git a/Cargo.toml b/Cargo.toml
index 076528f3..50653af4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@ name = "bindgen"
readme = "README.md"
repository = "https://github.com/rust-lang-nursery/rust-bindgen"
documentation = "https://docs.rs/bindgen"
-version = "0.30.0"
+version = "0.31.0"
build = "build.rs"
include = [
@@ -44,7 +44,7 @@ cexpr = "0.2"
cfg-if = "0.1.0"
# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982
clap = "2"
-clang-sys = { version = "0.19.0", features = ["runtime", "clang_3_9"] }
+clang-sys = { version = "0.21.0", features = ["runtime", "clang_3_9"] }
lazy_static = "0.2.1"
peeking_take_while = "0.1.2"
quote = "0.3.15"
diff --git a/README.md b/README.md
index 1dd3259b..4a233a98 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# `bindgen`
+[`impl period`](https://blog.rust-lang.org/2017/09/18/impl-future-for-rust.html) has been started! Join us at [Gitter.im](https://gitter.im/rust-impl-period/WG-dev-tools-bindgen).
+
**`bindgen` automatically generates Rust FFI bindings to C and C++ libraries.**
For example, given the C header `doggo.h`:
diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs
index fdb02dbb..b09b289d 100755
--- a/bindgen-integration/src/lib.rs
+++ b/bindgen-integration/src/lib.rs
@@ -183,8 +183,7 @@ fn test_bitfields_sixth() {
fn test_bitfield_constructors() {
use std::mem;
let mut first = bindings::bitfields::First {
- _bitfield_1: unsafe { mem::transmute(bindings::bitfields::First::new_bitfield_1(1, 2, 3)) },
- __bindgen_align: [],
+ _bitfield_1: unsafe { mem::transmute(bindings::bitfields::First::new_bitfield_1(1, 2, 3)) }
};
assert!(unsafe {
first.assert(1, 2, 3)
diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md
index 43d227c0..e070df8d 100644
--- a/book/src/SUMMARY.md
+++ b/book/src/SUMMARY.md
@@ -19,3 +19,4 @@
- [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md)
- [Generating Bindings to C++](./cpp.md)
- [Using Unions](./using-unions.md)
+- [FAQ](./faq.md)
diff --git a/book/src/cpp.md b/book/src/cpp.md
index 016caf1b..d181dec4 100644
--- a/book/src/cpp.md
+++ b/book/src/cpp.md
@@ -1,20 +1,10 @@
# Generating Bindings to C++
-`bindgen` can handle a surprising number of C++ features, but not all of
-them. When `bindgen` can't translate some C++ construct into Rust, it usually
-comes down to one of two things:
-
-1. Rust has no equivalent language feature
-2. C++ is *hard!*
-
-Notable C++ features that are unsupported or only partially supported, and for
-which `bindgen` *should* generate opaque blobs whenever it finds an occurrence
-of them in a type it is generating bindings for:
-
-* Template specialization
-* Partial template specialization
-* Traits templates
-* SFINAE
+`bindgen` can handle a some C++ features, but not all of them. To set
+expectations: `bindgen` will give you the type definitions and FFI declarations
+you need to build an API to the C++ library, but using those types in Rust will
+be nowhere near as nice as using them in C++. You will have to manually call
+constructors, destructors, overloaded operators, etc yourself.
When passing in header files, the file will automatically be treated as C++ if
it ends in `.hpp`. If it doesn't, adding `-x c++` clang args can be used to
@@ -23,5 +13,55 @@ as well.
You pretty much **must** use [whitelisting](./whitelisting.html) when working
with C++ to avoid pulling in all of the `std::*` types, many of which `bindgen`
-cannot handle. Additionally, you may want to mark other types
-as [opaque](./opaque.html) that `bindgen` stumbles on.
+cannot handle. Additionally, you may want to mark other types as
+[opaque](./opaque.html) that `bindgen` stumbles on. It is recommended to mark
+all of `std::*` opaque, and to whitelist only precisely the functions and types
+you intend to use.
+
+You should read up on the [FAQs](./faq.html) as well.
+
+## Supported Features
+
+* Inheritance (for the most part; there are
+ [some outstanding bugs](https://github.com/rust-lang-nursery/rust-bindgen/issues/380))
+
+* Methods
+
+* Bindings to constructors and destructors (but they aren't implicitly or
+ automatically invoked)
+
+* Function and method overloading
+
+* Templates *without* specialization. You should be able to access individual
+ fields of the class or struct.
+
+## Unsupported Features
+
+When `bindgen` finds a type that is too difficult or impossible to translate
+into Rust, it will automatically treat it as an opaque blob of bytes. The
+philosophy is that
+
+1. we should always get layout, size, and alignment correct, and
+
+2. just because one type uses specialization, that shouldn't cause `bindgen` to
+ give up on everything else.
+
+Without further ado, here are C++ features that `bindgen` does not support or
+cannot translate into Rust:
+
+* Inline functions and methods: see
+["Why isn't `bindgen` generating bindings to inline functions?"](./faq.html#why-isnt-bindgen-generating-bindings-to-inline-functions)
+
+* Template functions, methods of template classes and structs. We don't know
+ which monomorphizations exist, and can't create new ones because we aren't a
+ C++ compiler.
+
+* Anything related to template specialization:
+ * Partial template specialization
+ * Traits templates
+ * Specialization Failure Is Not An Error (SFINAE)
+
+* Cross language inheritance, for example inheriting from a Rust struct in C++.
+
+* Automatically calling copy and/or move constructors or destructors. Supporting
+ this isn't possible with Rust's move semantics.
diff --git a/book/src/faq.md b/book/src/faq.md
new file mode 100644
index 00000000..4f4bd820
--- /dev/null
+++ b/book/src/faq.md
@@ -0,0 +1,66 @@
+# Frequently Asked Questions
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+
+
+- [Why isn't `bindgen` generating methods for this whitelisted class?](#why-isnt-bindgen-generating-methods-for-this-whitelisted-class)
+- [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions)
+- [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+### Why isn't `bindgen` generating methods for this whitelisted class?
+
+Are the methods `inline` methods, or defined inline in the class? For example:
+
+```c++
+class Dooder {
+ public:
+ // Function defined inline in the class.
+ int example_one() { return 1; }
+
+ // `inline` function whose definition is supplied later in the header, or in
+ // another header.
+ inline bool example_two();
+};
+
+inline bool Dooder::example_two() {
+ return true;
+}
+```
+
+If so, see
+["Why isn't `bindgen` generating bindings to inline functions?"](#why-isnt-bindgen-generating-bindings-to-inline-functions)
+
+If not, consider filing an issue!
+
+### Why isn't `bindgen` generating bindings to inline functions?
+
+These functions don't typically end up in object files or shared libraries with
+symbols that we can reliably link to, since they are instead inlined into each
+of their call sites. Therefore, we don't generate bindings to them, since that
+creates linking errors.
+
+However, if you are compiling the C/C++ yourself (rather than using a system
+shared library, for example), then you can pass `-fkeep-inline-functions` or
+`-fno-inline-functions` to `gcc` or `clang`, and invoke `bindgen` with either
+the `bindgen::Builder::generate_inline_functions` method or the
+`--generate-inline-functions` flag.
+
+Note that these functions and methods are usually marked inline for a reason:
+they tend to be hot. The above workaround makes them an out-of-line call, which
+might not provide acceptable performance.
+
+### Does `bindgen` support the C++ Standard Template Library (STL)?
+
+Sort of. A little. Depends what you mean by "support".
+
+Most functions, methods, constructors, and destructors are inline in the
+STL. That ties our hands when it comes to linking: ["Why isn't `bindgen` generating bindings to inline functions?"](#why-isnt-bindgen-generating-bindings-to-inline-functions)
+
+As far as generating opaque blobs of bytes with the correct size and alignment,
+`bindgen` can do pretty well. This is typically enough to let you use types that
+transitively contain STL things. We generally recommend marking `std::.*` as
+opaque, and then whitelisting only the specific things you need from the library
+you're binding to that is pulling in STL headers.
diff --git a/book/src/nocopy.md b/book/src/nocopy.md
index 893f0932..06879ed1 100644
--- a/book/src/nocopy.md
+++ b/book/src/nocopy.md
@@ -6,6 +6,16 @@ Clone)]` to a translated type definition will compile, it still shouldn't do
that for reasons it can't know. In these cases, the `nocopy` annotation can be
used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type.
+###Library
+
+* [`bindgen::Builder::no_copy`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.no_copy)
+
+### Command Line
+
+* `--no-copy <regex>`
+
+### Annotations
+
```c
/**
* Although bindgen can't know, this struct is not safe to move because pthread
diff --git a/csmith-fuzzing/README.md b/csmith-fuzzing/README.md
new file mode 100644
index 00000000..c7e8eaf9
--- /dev/null
+++ b/csmith-fuzzing/README.md
@@ -0,0 +1,65 @@
+# Fuzzing `bindgen` with `csmith`
+
+[`csmith`][csmith] generates random C and C++ programs that can be used as test
+cases for compilers. When testing `bindgen` with `csmith`, we interpret the
+generated programs as header files, and emit Rust bindings to them. If `bindgen`
+panics, the emitted bindings won't compile with `rustc`, or the generated layout
+tests in the bindings fail, then we report an issue containing the test case!
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+
+
+- [Prerequisites](#prerequisites)
+- [Running the Fuzzer](#running-the-fuzzer)
+- [Reporting Issues](#reporting-issues)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+## Prerequisites
+
+Requires `python3`, `csmith`, and `creduce` to be in `$PATH`.
+
+Many OS package managers have `csmith` and `creduce` packages:
+
+```
+$ sudo apt install csmith creduce
+$ brew install csmith creduce
+$ # Etc...
+```
+
+## Running the Fuzzer
+
+Run `csmith` and test `bindgen` on the generated test cases with this command:
+
+```
+$ ./driver.py
+```
+
+The driver will keep running until it encounters an error in `bindgen`.
+
+Each invocation of `./driver.py` will use its own temporary directories, so
+running it in multiple terminals in parallel is supported.
+
+`csmith` is run with `--no-checksum --nomain --max-block-size 1
+--max-block-depth 1` which disables the `main` function, and makes function
+bodies as simple as possible as `bindgen` does not care about them, but they
+cannot be completely disabled in `csmith`. Run `csmith --help` to see what
+exactly those options do.
+
+## Reporting Issues
+
+Once the fuzz driver finds a test case that causes some kind of error in
+`bindgen` or its emitted bindings, it is helpful to
+[run C-Reduce on the test case][creducing] to remove the parts that are
+irrelevant to reproducing the error. This is ***very*** helpful for the folks
+who further investigate the issue and come up with a fix!
+
+Additionally, mention that you discovered the issue via `csmith` and we will add
+the `A-csmith` label. You can find all the issues discovered with `csmith`, and
+related to fuzzing with `csmith`, by looking up
+[all issues tagged with the `A-csmith` label][csmith-issues].
+
+[csmith]: https://github.com/csmith-project/csmith
+[creducing]: ../CONTRIBUTING.md#using-creduce-to-minimize-test-cases
+[csmith-issues]: https://github.com/rust-lang-nursery/rust-bindgen/issues?q=label%3AA-csmith
diff --git a/csmith-fuzzing/csmith.h b/csmith-fuzzing/csmith.h
new file mode 100644
index 00000000..faaef5b1
--- /dev/null
+++ b/csmith-fuzzing/csmith.h
@@ -0,0 +1,15 @@
+// Type definitions from csmith's csmith_minimal.h included in csmith.h .
+// Since other header contents are not needed we put them in here
+// so the other original header is not needed anymore.
+
+#define int8_t signed char
+#define uint8_t unsigned char
+
+#define int16_t short
+#define uint16_t unsigned short
+
+#define int32_t int
+#define uint32_t unsigned
+
+#define int64_t long long
+#define uint64_t unsigned long long
diff --git a/csmith-fuzzing/driver.py b/csmith-fuzzing/driver.py
new file mode 100755
index 00000000..8bf76e0b
--- /dev/null
+++ b/csmith-fuzzing/driver.py
@@ -0,0 +1,284 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import re
+import shlex
+import sys
+from subprocess import run, SubprocessError, DEVNULL, PIPE
+from tempfile import NamedTemporaryFile
+
+DESC = """
+
+A `csmith` fuzzing driver for `bindgen`.
+
+Generates random C source files with `csmith` and then passes them to `bindgen`
+(via `predicate.py`). If `bindgen` can't emit bindings, `rustc` can't compile
+those bindings, or the compiled bindings' layout tests fail, then the driver has
+found a bug, and will report the problematic test case to you.
+
+"""
+
+parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=DESC.strip())
+
+parser.add_argument(
+ "--keep-going",
+ action="store_true",
+ help="Do not stop after finding a test case that exhibits a bug in `bindgen`. Instead, keep going.")
+
+CSMITH_ARGS="\
+--no-checksum \
+--nomain \
+--max-block-size 1 \
+--max-block-depth 1"
+
+parser.add_argument(
+ "--csmith-args",
+ type=str,
+ default=CSMITH_ARGS,
+ help="Pass this argument string to `csmith`. By default, very small functions are generated.")
+
+BINDGEN_ARGS = "--with-derive-partialeq \
+--with-derive-eq \
+--with-derive-partialord \
+--with-derive-ord \
+--with-derive-hash \
+--with-derive-default"
+
+parser.add_argument(
+ "--bindgen-args",
+ type=str,
+ default=BINDGEN_ARGS,
+ help="Pass this argument string to `bindgen`. By default, all traits are derived.")
+
+parser.add_argument(
+ "--no-creduce",
+ action="store_false",
+ dest="creduce",
+ help="Do not run `creduce` on any buggy test case(s) discovered.")
+
+################################################################################
+
+def cat(path, title=None):
+ if not title:
+ title = path
+ print("-------------------- {} --------------------".format(title))
+ print()
+ print()
+ run(["cat", path])
+
+def decode(f):
+ return f.decode(encoding="utf-8", errors="ignore")
+
+def run_logged(cmd):
+ result = run(cmd, stdin=DEVNULL, stdout=PIPE, stderr=PIPE)
+ result.stdout = decode(result.stdout)
+ result.stderr = decode(result.stderr)
+ if result.returncode != 0:
+ print()
+ print()
+ print("Error: {} exited with code {}".format(cmd, result.returncode))
+ print()
+ print()
+ for line in result.stdout.splitlines():
+ sys.stdout.write("+")
+ sys.stdout.write(line)
+ sys.stdout.write("\n")
+ for line in result.stderr.splitlines():
+ sys.stderr.write("+")
+ sys.stderr.write(line)
+ sys.stderr.write("\n")
+ return result
+
+def main():
+ os.environ["RUST_BACKTRACE"] = "full"
+ args = parser.parse_args()
+
+ bindgen_args = args.bindgen_args
+ if bindgen_args.find(" -- ") == -1:
+ bindgen_args = bindgen_args + " -- "
+ bindgen_args = bindgen_args + " -I{}".format(os.path.abspath(os.path.dirname(sys.argv[0])))
+ args.bindgen_args = bindgen_args
+
+ print()
+ print()
+ print("Fuzzing `bindgen` with C-Smith...")
+ print()
+ print()
+
+ iterations = 0
+ while True:
+ print("\rIteration: {}".format(iterations), end="", flush=True)
+ iterations += 1
+
+ input = NamedTemporaryFile(delete=False, prefix="input-", suffix=".h")
+ input.close()
+ result = run_logged(["csmith", "-o", input.name] + shlex.split(args.csmith_args))
+ if result.returncode != 0:
+ exit(1)
+
+ predicate_command = [
+ "./predicate.py",
+ "--bindgen-args",
+ args.bindgen_args,
+ input.name
+ ]
+ result = run_logged(predicate_command)
+
+ if result.returncode != 0:
+ print()
+ print()
+ cat(input.name, title="Failing test case: {}".format(input.name))
+ print()
+ print()
+
+ if args.creduce:
+ creduce(args, input.name, result)
+
+ print_issue_template(args, input.name, predicate_command, result)
+
+ if args.keep_going:
+ continue
+ exit(1)
+
+ os.remove(input.name)
+
+RUSTC_ERROR_REGEX = re.compile(r".*(error\[.*].*)")
+LAYOUT_TEST_FAILURE = re.compile(r".*(test bindgen_test_layout_.* \.\.\. FAILED)")
+
+def creduce(args, failing_test_case, result):
+ print()
+ print()
+ print("Reducing failing test case with `creduce`...")
+
+ match = re.search(RUSTC_ERROR_REGEX, result.stderr)
+ if match:
+ error_msg = match.group(1)
+ print("...searching for \"{}\".".format(error_msg))
+ return creduce_with_predicate_flags(
+ args,
+ failing_test_case,
+ "--bindgen-args '{}' --expect-compile-fail --rustc-grep '{}'".format(
+ args.bindgen_args,
+ re.escape(error_msg)
+ )
+ )
+
+ match = re.search(LAYOUT_TEST_FAILURE, result.stdout)
+ if match:
+ layout_failure = match.group(1)
+ struct_name = layout_failure[len("test bindgen_test_layout_"):layout_failure.rindex(" ... FAILED")]
+ print("...searching for \"{}\".".format(layout_failure))
+ return creduce_with_predicate_flags(
+ args,
+ failing_test_case,
+ "--bindgen-args '{}' --expect-layout-tests-fail --bindings-grep '{}' --layout-tests-grep '{}'".format(
+ args.bindgen_args,
+ re.escape(struct_name),
+ re.escape(layout_failure)
+ )
+ )
+
+ print("...nevermind, don't know how to `creduce` this bug. Skipping.")
+
+def creduce_with_predicate_flags(args, failing_test_case, predicate_flags):
+ predicate = """
+#!/usr/bin/env bash
+set -eu
+{} {} {}
+ """.format(
+ os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "predicate.py")),
+ predicate_flags,
+ os.path.basename(failing_test_case)
+ )
+
+ print("...and reducing with this script:")
+ print()
+ print()
+ print(predicate)
+ print()
+ print()
+
+ predicate_path = failing_test_case + ".predicate.sh"
+ with open(predicate_path, "w") as p:
+ p.write(predicate)
+ os.chmod(predicate_path, 0o755)
+
+ creduce_command = ["creduce", "--n", str(os.cpu_count()), predicate_path, failing_test_case]
+ print("Running:", creduce_command)
+ result = run(creduce_command)
+ if result.returncode == 0:
+ print()
+ print()
+ print("`creduce` reduced the failing test case to:")
+ print()
+ print()
+ cat(failing_test_case)
+ print()
+ print()
+ else:
+ print()
+ print()
+ print("`creduce` failed!")
+ if not args.keep_going:
+ sys.exit(1)
+
+def print_issue_template(args, failing_test_case, predicate_command, result):
+ test_case_contents = None
+ with open(failing_test_case, "r") as f:
+ test_case_contents = f.read()
+
+ print("""
+
+! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
+! File this issue at https://github.com/rust-lang-nursery/rust-bindgen/issues/new !
+! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
+
+ --------------- 8< --------------- 8< --------------- 8< ---------------
+
+This bug was found with `csmith` and `driver.py`.
+
+### Input Header
+
+```c
+{}
+```
+
+### `bindgen` Invocation
+
+```
+$ {}
+```
+
+### Actual Results
+
+<details>
+
+```
+{}
+```
+
+</details>
+
+### Expected Results
+
+`bindgen` emits bindings OK, then `rustc` compiles those bindings OK, then the
+compiled bindings' layout tests pass OK.
+
+ --------------- 8< --------------- 8< --------------- 8< ---------------
+
+ <3 <3 <3 Thank you! <3 <3 <3
+ """.format(
+ test_case_contents,
+ " ".join(map(lambda s: "'{}'".format(s), predicate_command)),
+ result.stdout + result.stderr
+ ))
+
+if __name__ == "__main__":
+ try:
+ os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
+ main()
+ except KeyboardInterrupt:
+ exit()
diff --git a/csmith-fuzzing/predicate.py b/csmith-fuzzing/predicate.py
new file mode 100755
index 00000000..91e4e26d
--- /dev/null
+++ b/csmith-fuzzing/predicate.py
@@ -0,0 +1,254 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import re
+import shlex
+import subprocess
+import sys
+from tempfile import NamedTemporaryFile
+
+DESC = """
+
+Determine whether `bindgen` can successfully process a C or C++ input header.
+
+First, `bindgen` is run on the input header. Then the emitted bindings are
+compiled with `rustc`. Finally, the compiled bindings' layout tests are run.
+
+By default, this script will exit zero if all of the above steps are successful,
+and non-zero if any of them fail. This is appropriate for determining if some
+test case (perhaps generated with `csmith` or another fuzzer) uncovers any bugs
+in `bindgen`.
+
+However, this script can also be used when reducing (perhaps with `creduce`) a
+known-bad test case into a new, smaller test case that exhibits the same bad
+behavior. In this mode, you might expect that the emitted bindings fail to
+compile with `rustc`, and want to exit non-zero early if that is not the
+case. See the "reducing arguments" for details and what knobs are available.
+
+"""
+
+parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=DESC.strip())
+
+BINDGEN_ARGS = "--with-derive-partialeq \
+--with-derive-eq \
+--with-derive-partialord \
+--with-derive-ord \
+--with-derive-hash \
+--with-derive-default"
+
+parser.add_argument(
+ "--bindgen-args",
+ type=str,
+ default=BINDGEN_ARGS,
+ help="An argument string that `bindgen` should be invoked with. By default, all traits are derived. Note that the input header and output bindings file will automatically be provided by this script, and you should not manually specify them.")
+
+parser.add_argument(
+ "input",
+ type=str,
+ default="input.h",
+ help="The input header file. Defaults to 'input.h'.")
+
+REDUCING_DESC = """
+
+Arguments that are useful when reducing known-bad test cases into
+equivalent-but-smaller test cases that exhibit the same bug with `creduce`.
+
+"""
+
+reducing = parser.add_argument_group("reducing arguments", REDUCING_DESC.strip())
+
+reducing.add_argument(
+ "--expect-bindgen-fail",
+ action="store_true",
+ help="Exit non-zero if `bindgen` successfully emits bindings.")
+reducing.add_argument(
+ "--bindgen-grep",
+ type=str,
+ help="Exit non-zero if the given regexp pattern is not found in `bindgen`'s output.")
+reducing.add_argument(
+ "--bindings-grep",
+ type=str,
+ help="Exit non-zero if the given regexp pattern is not found in the emitted bindings.")
+
+reducing.add_argument(
+ "--no-compile-bindings",
+ action="store_false",
+ dest="rustc",
+ help="Do not attempt to compile the emitted bindings with `rustc`.")
+reducing.add_argument(
+ "--expect-compile-fail",
+ action="store_true",
+ help="Exit non-zero if `rustc` successfully compiles the emitted bindings.")
+reducing.add_argument(
+ "--rustc-grep",
+ type=str,
+ help="Exit non-zero if the output from compiling the bindings with `rustc` does not contain the given regexp pattern")
+
+reducing.add_argument(
+ "--no-layout-tests",
+ action="store_false",
+ dest="layout_tests",
+ help="Do not run the compiled bindings' layout tests.")
+reducing.add_argument(
+ "--expect-layout-tests-fail",
+ action="store_true",
+ help="Exit non-zero if the compiled bindings' layout tests pass.")
+reducing.add_argument(
+ "--layout-tests-grep",
+ type=str,
+ help="Exit non-zero if the output of running the compiled bindings' layout tests does not contain the given regexp pattern.")
+
+################################################################################
+
+class ExitOne(Exception):
+ pass
+
+def exit_1(msg, child=None):
+ print(msg)
+
+ if child:
+ stdout = decode(child.stdout)
+ for line in stdout.splitlines():
+ sys.stdout.write("+")
+ sys.stdout.write(line)
+ sys.stdout.write("\n")
+ stderr = decode(child.stderr)
+ for line in stderr.splitlines():
+ sys.stderr.write("+")
+ sys.stderr.write(line)
+ sys.stderr.write("\n")
+
+ raise ExitOne()
+
+def main():
+ args = parser.parse_args()
+ os.environ["RUST_BACKTRACE"] = "full"
+
+ exit_code = 0
+ try:
+ bindings = new_temp_file(prefix="bindings-", suffix=".rs")
+ run_bindgen(args, bindings)
+
+ if args.rustc and not args.expect_bindgen_fail:
+ test_exe = new_temp_file(prefix="layout-tests-")
+ run_rustc(args, bindings, test_exe)
+
+ if args.layout_tests and not args.expect_compile_fail:
+ run_layout_tests(args, test_exe)
+ except ExitOne:
+ exit_code = 1
+ except Exception as e:
+ exit_code = 2
+ print("Unexpected exception:", e)
+
+ for p in TEMP_FILES:
+ try:
+ os.remove(path)
+ except:
+ pass
+
+ sys.exit(exit_code)
+
+def run(cmd, **kwargs):
+ print("Running:", cmd)
+ return subprocess.run(cmd, **kwargs)
+
+def decode(f):
+ return f.decode(encoding="utf-8", errors="ignore")
+
+TEMP_FILES = []
+
+def new_temp_file(prefix, suffix=None):
+ temp = NamedTemporaryFile(delete=False, prefix=prefix, suffix=suffix)
+ temp.close()
+ TEMP_FILES.append(temp.name)
+ return temp.name
+
+def contains(pattern, lines):
+ for line in lines:
+ if re.match(pattern, line):
+ return True
+ return False
+
+def regexp(pattern):
+ if not pattern.startswith("^"):
+ pattern = ".*" + pattern
+ if not pattern.endswith("$"):
+ pattern = pattern + ".*"
+ return re.compile(pattern)
+
+def run_bindgen(args, bindings):
+ manifest_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),
+ "..",
+ "Cargo.toml"))
+ child = run(
+ ["cargo", "run",
+ "--manifest-path", manifest_path,
+ "--",
+ args.input, "-o", bindings] + shlex.split(args.bindgen_args),
+ stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+
+ if args.bindgen_grep:
+ pattern = regexp(args.bindgen_grep)
+ if not (contains(pattern, decode(child.stdout).splitlines()) or
+ contains(pattern, decode(child.stderr).splitlines())):
+ exit_1("Error: did not find '{}' in `bindgen`'s output".format(args.bindgen_grep), child)
+
+ if args.expect_bindgen_fail and child.returncode == 0:
+ exit_1("Error: expected running `bindgen` to fail, but it didn't", child)
+
+ if not args.expect_bindgen_fail and child.returncode != 0:
+ exit_1("Error: running `bindgen` failed", child)
+
+ if args.bindings_grep:
+ pattern = regexp(args.bindings_grep)
+ with open(bindings, mode="r") as f:
+ if not contains(pattern, f):
+ print("Error: expected the emitted bindings to contain '{}', but they didn't".format(args.bindings_grep))
+ print("---------- {} ----------------------------------------------".format(bindings))
+ f.seek(0)
+ print(f.read())
+ raise ExitOne()
+
+def run_rustc(args, bindings, test_exe):
+ child = run(
+ ["rustc", "--crate-type", "lib", "--test", "-o", test_exe, bindings],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+
+ if args.rustc_grep:
+ pattern = regexp(args.rustc_grep)
+ if not (contains(pattern, decode(child.stdout).splitlines()) or
+ contains(pattern, decode(child.stderr).splitlines())):
+ exit_1("Error: did not find '{}' in `rustc`'s output".format(args.rustc_grep), child)
+
+ if args.expect_compile_fail and child.returncode == 0:
+ exit_1("Error: expected running `rustc` on the emitted bindings to fail, but it didn't", child)
+
+ if not args.expect_compile_fail and child.returncode != 0:
+ exit_1("Error: running `rustc` on the emitted bindings failed", child)
+
+def run_layout_tests(args, test_exe):
+ child = run(
+ [test_exe],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+
+ if args.layout_tests_grep:
+ pattern = regexp(args.layout_tests_grep)
+ if not (contains(pattern, decode(child.stdout).splitlines()) or
+ contains(pattern, decode(child.stderr).splitlines())):
+ exit_1("Error: did not find '{}' in the compiled bindings' layout tests' output".format(args.layout_tests_grep), child)
+
+ if args.expect_layout_tests_fail and child.returncode == 0:
+ exit_1("Error: expected running the compiled bindings' layout tests to fail, but it didn't", child)
+
+ if not args.expect_layout_tests_fail and child.returncode != 0:
+ exit_1("Error: running the compiled bindings' layout tests failed", child)
+
+if __name__ == "__main__":
+ main()
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 5136d787..4ff398c4 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -45,6 +45,9 @@ pub mod attributes {
}
pub fn link_name(name: &str) -> quote::Tokens {
+ // LLVM mangles the name by default but it's already mangled.
+ // Prefixing the name with \u{1} should tell LLVM to not mangle it.
+ let name = format!("\u{1}{}", name);
quote! {
#[link_name = #name]
}
@@ -140,6 +143,13 @@ pub mod ast_ty {
tokens
}
+ /// Returns hex representation of the given value.
+ pub fn hex_expr(val: u64) -> quote::Tokens {
+ let mut tokens = quote! {};
+ tokens.append(format!("{:#x}", val));
+ tokens
+ }
+
pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens {
let mut bytes: Vec<_> = bytes.iter().cloned().collect();
bytes.push(0);
diff --git a/src/codegen/derive_debug.rs b/src/codegen/impl_debug.rs
index 7ef108da..e0204f4d 100644
--- a/src/codegen/derive_debug.rs
+++ b/src/codegen/impl_debug.rs
@@ -28,7 +28,6 @@ pub fn gen_debug_impl(
&Field::Bitfields(ref bu) => bu.impl_debug(ctx, ()),
});
-
for (i, (fstring, toks)) in processed_fields.enumerate() {
if i > 0 {
format_string.push_str(", ");
@@ -91,15 +90,19 @@ impl<'a> ImplDebug<'a> for BitfieldUnit {
) -> Option<(String, Vec<quote::Tokens>)> {
let mut format_string = String::new();
let mut tokens = vec![];
- for (i, bu) in self.bitfields().iter().enumerate() {
+ for (i, bitfield) in self.bitfields().iter().enumerate() {
if i > 0 {
format_string.push_str(", ");
}
- format_string.push_str(&format!("{} : {{:?}}", bu.name()));
- let name_ident = ctx.rust_ident_raw(bu.name());
- tokens.push(quote! {
- self.#name_ident ()
- });
+
+ if let Some(bitfield_name) = 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! {
+ self.#name_ident ()
+ });
+ }
}
Some((format_string, tokens))
diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs
new file mode 100644
index 00000000..02783808
--- /dev/null
+++ b/src/codegen/impl_partialeq.rs
@@ -0,0 +1,125 @@
+
+use ir::comp::{CompInfo, CompKind, Field, FieldMethods};
+use ir::context::BindgenContext;
+use ir::item::{IsOpaque, Item};
+use ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT};
+use quote;
+
+/// Generate a manual implementation of `PartialEq` trait for the
+/// specified compound type.
+pub fn gen_partialeq_impl(
+ ctx: &BindgenContext,
+ comp_info: &CompInfo,
+ item: &Item,
+ ty_for_impl: &quote::Tokens,
+) -> Option<quote::Tokens> {
+ let mut tokens = vec![];
+
+ if item.is_opaque(ctx, &()) {
+ tokens.push(quote! {
+ &self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..]
+ });
+ } else if comp_info.kind() == CompKind::Union {
+ assert!(!ctx.options().rust_features().untagged_union());
+ tokens.push(quote! {
+ &self.bindgen_union_field[..] == &other.bindgen_union_field[..]
+ });
+ } else {
+ for base in comp_info.base_members().iter() {
+ if !base.requires_storage(ctx) {
+ continue;
+ }
+
+ let ty_item = ctx.resolve_item(base.ty);
+ let field_name = &base.field_name;
+
+ if ty_item.is_opaque(ctx, &()) {
+ let field_name = ctx.rust_ident(field_name);
+ tokens.push(quote! {
+ &self. #field_name [..] == &other. #field_name [..]
+ });
+ } else {
+ tokens.push(gen_field(ctx, ty_item, field_name));
+ }
+ }
+
+ for field in comp_info.fields() {
+ match *field {
+ Field::DataMember(ref fd) => {
+ let ty_item = ctx.resolve_item(fd.ty());
+ let name = fd.name().unwrap();
+ tokens.push(gen_field(ctx, ty_item, name));
+ }
+ Field::Bitfields(ref bu) => for bitfield in bu.bitfields() {
+ if let Some(_) = bitfield.name() {
+ let getter_name = bitfield.getter_name();
+ let name_ident = ctx.rust_ident_raw(getter_name);
+ tokens.push(quote! {
+ self.#name_ident () == other.#name_ident ()
+ });
+ }
+ },
+ }
+ }
+ }
+
+ Some(quote! {
+ fn eq(&self, other: & #ty_for_impl) -> bool {
+ #( #tokens )&&*
+ }
+ })
+}
+
+fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> quote::Tokens {
+ fn quote_equals(name_ident: quote::Ident) -> quote::Tokens {
+ quote! { self.#name_ident == other.#name_ident }
+ }
+
+ let name_ident = ctx.rust_ident(name);
+ let ty = ty_item.expect_type();
+
+ match *ty.kind() {
+ TypeKind::Void |
+ TypeKind::NullPtr |
+ TypeKind::Int(..) |
+ TypeKind::Complex(..) |
+ TypeKind::Float(..) |
+ TypeKind::Enum(..) |
+ TypeKind::TypeParam |
+ TypeKind::UnresolvedTypeRef(..) |
+ TypeKind::BlockPointer |
+ TypeKind::Reference(..) |
+ TypeKind::ObjCInterface(..) |
+ TypeKind::ObjCId |
+ TypeKind::ObjCSel |
+ TypeKind::Comp(..) |
+ TypeKind::Pointer(_) |
+ TypeKind::Function(..) |
+ TypeKind::Opaque => quote_equals(name_ident),
+
+ TypeKind::TemplateInstantiation(ref inst) => {
+ if inst.is_opaque(ctx, &ty_item) {
+ quote! {
+ &self. #name_ident [..] == &other. #name_ident [..]
+ }
+ } else {
+ quote_equals(name_ident)
+ }
+ }
+
+ TypeKind::Array(_, len) => if len <= RUST_DERIVE_IN_ARRAY_LIMIT {
+ quote_equals(name_ident)
+ } else {
+ quote! {
+ &self. #name_ident [..] == &other. #name_ident [..]
+ }
+ },
+
+ TypeKind::ResolvedTypeRef(t) |
+ TypeKind::TemplateAlias(t, _) |
+ TypeKind::Alias(t) => {
+ let inner_item = ctx.resolve_item(t);
+ gen_field(ctx, inner_item, name)
+ }
+ }
+}
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index e0d4e46d..6c1ed02f 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1,4 +1,5 @@
-mod derive_debug;
+mod impl_debug;
+mod impl_partialeq;
mod error;
mod helpers;
pub mod struct_layout;
@@ -6,16 +7,20 @@ pub mod struct_layout;
use self::helpers::attributes;
use self::struct_layout::StructLayoutTracker;
+use super::BindgenOptions;
+
+use ir::analysis::{HasVtable, Sizedness};
use ir::annotations::FieldAccessorKind;
use ir::comment;
use ir::comp::{Base, Bitfield, BitfieldUnit, CompInfo, CompKind, Field,
FieldData, FieldMethods, Method, MethodKind};
use ir::context::{BindgenContext, ItemId};
use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault,
- CanDeriveHash, CanDerivePartialEq, CanDeriveEq};
+ CanDeriveHash, CanDerivePartialOrd, CanDeriveOrd,
+ CanDerivePartialEq, CanDeriveEq, CannotDeriveReason};
use ir::dot;
use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue};
-use ir::function::{Abi, Function, FunctionSig};
+use ir::function::{Abi, Function, FunctionSig, Linkage};
use ir::int::IntKind;
use ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath};
use ir::item_kind::ItemKind;
@@ -150,12 +155,12 @@ impl<'a> CodegenResult<'a> {
self.saw_objc = true;
}
- fn seen(&self, item: ItemId) -> bool {
- self.items_seen.contains(&item)
+ fn seen<Id: Into<ItemId>>(&self, item: Id) -> bool {
+ self.items_seen.contains(&item.into())
}
- fn set_seen(&mut self, item: ItemId) {
- self.items_seen.insert(item);
+ fn set_seen<Id: Into<ItemId>>(&mut self, item: Id) {
+ self.items_seen.insert(item.into());
}
fn seen_function(&self, name: &str) -> bool {
@@ -473,7 +478,19 @@ impl CodeGenerator for Var {
});
}
VarType::Int(val) => {
- let val = helpers::ast_ty::int_expr(val);
+ let int_kind = self.ty()
+ .into_resolver()
+ .through_type_aliases()
+ .through_type_refs()
+ .resolve(ctx)
+ .expect_type()
+ .as_integer()
+ .unwrap();
+ let val = if int_kind.is_signed() {
+ helpers::ast_ty::int_expr(val)
+ } else {
+ helpers::ast_ty::uint_expr(val as _)
+ };
result.push(quote! {
pub const #canonical_ident : #ty = #val ;
});
@@ -598,7 +615,7 @@ impl CodeGenerator for Type {
// If this is a known named type, disallow generating anything
// for it too.
let spelling = self.name().expect("Unnamed alias?");
- if utils::type_from_named(ctx, spelling, inner).is_some() {
+ if utils::type_from_named(ctx, spelling).is_some() {
return;
}
@@ -864,24 +881,6 @@ impl CodeGenerator for TemplateInstantiation {
}
}
-/// Generates an infinite number of anonymous field names.
-struct AnonFieldNames(usize);
-
-impl Default for AnonFieldNames {
- fn default() -> AnonFieldNames {
- AnonFieldNames(0)
- }
-}
-
-impl Iterator for AnonFieldNames {
- type Item = String;
-
- fn next(&mut self) -> Option<String> {
- self.0 += 1;
- Some(format!("__bindgen_anon_{}", self.0))
- }
-}
-
/// Trait for implementing the code generation of a struct or union field.
trait FieldCodegen<'a> {
type Extra;
@@ -893,7 +892,6 @@ trait FieldCodegen<'a> {
codegen_depth: usize,
accessor_kind: FieldAccessorKind,
parent: &CompInfo,
- anon_field_names: &mut AnonFieldNames,
result: &mut CodegenResult,
struct_layout: &mut StructLayoutTracker,
fields: &mut F,
@@ -914,7 +912,6 @@ impl<'a> FieldCodegen<'a> for Field {
codegen_depth: usize,
accessor_kind: FieldAccessorKind,
parent: &CompInfo,
- anon_field_names: &mut AnonFieldNames,
result: &mut CodegenResult,
struct_layout: &mut StructLayoutTracker,
fields: &mut F,
@@ -932,7 +929,6 @@ impl<'a> FieldCodegen<'a> for Field {
codegen_depth,
accessor_kind,
parent,
- anon_field_names,
result,
struct_layout,
fields,
@@ -947,7 +943,6 @@ impl<'a> FieldCodegen<'a> for Field {
codegen_depth,
accessor_kind,
parent,
- anon_field_names,
result,
struct_layout,
fields,
@@ -969,7 +964,6 @@ impl<'a> FieldCodegen<'a> for FieldData {
codegen_depth: usize,
accessor_kind: FieldAccessorKind,
parent: &CompInfo,
- anon_field_names: &mut AnonFieldNames,
result: &mut CodegenResult,
struct_layout: &mut StructLayoutTracker,
fields: &mut F,
@@ -981,7 +975,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
{
// Bitfields are handled by `FieldCodegen` implementations for
// `BitfieldUnit` and `Bitfield`.
- assert!(self.bitfield().is_none());
+ assert!(self.bitfield_width().is_none());
let field_item = self.ty().into_resolver().through_type_refs().resolve(ctx);
let field_ty = field_item.expect_type();
@@ -1029,7 +1023,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
let field_name =
self.name()
.map(|name| ctx.rust_mangle(name).into_owned())
- .unwrap_or_else(|| anon_field_names.next().unwrap());
+ .expect("Each field should have a name in codegen!");
let field_ident = ctx.rust_ident_raw(field_name.as_str());
if !parent.is_union() {
@@ -1141,7 +1135,7 @@ impl Bitfield {
let bitfield_int_ty = helpers::blob(bitfield_ty_layout);
let offset = self.offset_into_unit();
- let mask = self.mask();
+ let mask = helpers::ast_ty::hex_expr(self.mask());
// Don't use variables or blocks because const functions do not allow
// them.
@@ -1163,7 +1157,6 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
codegen_depth: usize,
accessor_kind: FieldAccessorKind,
parent: &CompInfo,
- anon_field_names: &mut AnonFieldNames,
result: &mut CodegenResult,
struct_layout: &mut StructLayoutTracker,
fields: &mut F,
@@ -1173,7 +1166,21 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
F: Extend<quote::Tokens>,
M: Extend<quote::Tokens>,
{
- let field_ty = helpers::blob(self.layout());
+ let field_ty = if parent.is_union() && !parent.can_be_rust_union(ctx) {
+ let ty = helpers::blob(self.layout());
+ if ctx.options().enable_cxx_namespaces {
+ quote! {
+ root::__BindgenUnionField<#ty>
+ }
+ } else {
+ quote! {
+ __BindgenUnionField<#ty>
+ }
+ }
+ } else {
+ helpers::blob(self.layout())
+ };
+
let unit_field_name = format!("_bitfield_{}", self.nth());
let unit_field_ident = ctx.rust_ident(&unit_field_name);
@@ -1206,13 +1213,16 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
let mut ctor_impl = quote! { 0 };
for bf in self.bitfields() {
+ // Codegen not allowed for anonymous bitfields
+ if bf.name().is_none() {
+ continue;
+ }
bf.codegen(
ctx,
fields_should_be_private,
codegen_depth,
accessor_kind,
parent,
- anon_field_names,
result,
struct_layout,
fields,
@@ -1220,7 +1230,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
(&unit_field_name, unit_field_int_ty.clone()),
);
- let param_name = bitfield_getter_name(ctx, parent, bf.name());
+ let param_name = bitfield_getter_name(ctx, bf);
let bitfield_ty_item = ctx.resolve_item(bf.ty());
let bitfield_ty = bitfield_ty_item.expect_type();
let bitfield_ty =
@@ -1254,59 +1264,21 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
}
}
-fn parent_has_method(
- ctx: &BindgenContext,
- parent: &CompInfo,
- name: &str,
-) -> bool {
- parent.methods().iter().any(|method| {
- let method_name = match *ctx.resolve_item(method.signature()).kind() {
- ItemKind::Function(ref func) => func.name(),
- ref otherwise => {
- panic!(
- "a method's signature should always be a \
- item of kind ItemKind::Function, found: \
- {:?}",
- otherwise
- )
- }
- };
-
- method_name == name || ctx.rust_mangle(&method_name) == name
- })
-}
-
fn bitfield_getter_name(
ctx: &BindgenContext,
- parent: &CompInfo,
- bitfield_name: &str,
+ bitfield: &Bitfield,
) -> quote::Tokens {
- let name = ctx.rust_mangle(bitfield_name);
-
- if parent_has_method(ctx, parent, &name) {
- let mut name = name.to_string();
- name.push_str("_bindgen_bitfield");
- let name = ctx.rust_ident(name);
- return quote! { #name };
- }
-
- let name = ctx.rust_ident(name);
+ let name = bitfield.getter_name();
+ let name = ctx.rust_ident_raw(name);
quote! { #name }
}
fn bitfield_setter_name(
ctx: &BindgenContext,
- parent: &CompInfo,
- bitfield_name: &str,
+ bitfield: &Bitfield,
) -> quote::Tokens {
- let setter = format!("set_{}", bitfield_name);
- let mut setter = ctx.rust_mangle(&setter).to_string();
-
- if parent_has_method(ctx, parent, &setter) {
- setter.push_str("_bindgen_bitfield");
- }
-
- let setter = ctx.rust_ident(setter);
+ let setter = bitfield.setter_name();
+ let setter = ctx.rust_ident_raw(setter);
quote! { #setter }
}
@@ -1319,8 +1291,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
_fields_should_be_private: bool,
_codegen_depth: usize,
_accessor_kind: FieldAccessorKind,
- parent: &CompInfo,
- _anon_field_names: &mut AnonFieldNames,
+ _parent: &CompInfo,
_result: &mut CodegenResult,
_struct_layout: &mut StructLayoutTracker,
_fields: &mut F,
@@ -1331,8 +1302,8 @@ impl<'a> FieldCodegen<'a> for Bitfield {
M: Extend<quote::Tokens>,
{
let prefix = ctx.trait_prefix();
- let getter_name = bitfield_getter_name(ctx, parent, self.name());
- let setter_name = bitfield_setter_name(ctx, parent, self.name());
+ let getter_name = bitfield_getter_name(ctx, self);
+ let setter_name = bitfield_setter_name(ctx, self);
let unit_field_ident = quote::Ident::new(unit_field_name);
let bitfield_ty_item = ctx.resolve_item(self.ty());
@@ -1347,7 +1318,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
bitfield_ty.to_rust_ty_or_opaque(ctx, bitfield_ty_item);
let offset = self.offset_into_unit();
- let mask = self.mask();
+ let mask = helpers::ast_ty::hex_expr(self.mask());
methods.extend(Some(quote! {
#[inline]
@@ -1423,6 +1394,8 @@ impl CodeGenerator for CompInfo {
let used_template_params = item.used_template_params(ctx);
+ let mut packed = self.packed();
+
// generate tuple struct if struct or union is a forward declaration,
// skip for now if template parameters are needed.
//
@@ -1440,80 +1413,8 @@ impl CodeGenerator for CompInfo {
return;
}
- let mut attributes = vec![];
- let mut needs_clone_impl = false;
- let mut needs_default_impl = false;
- let mut needs_debug_impl = false;
- if let Some(comment) = item.comment(ctx) {
- attributes.push(attributes::doc(comment));
- }
- if self.packed() {
- attributes.push(attributes::repr_list(&["C", "packed"]));
- } else {
- attributes.push(attributes::repr("C"));
- }
-
- let is_union = self.kind() == CompKind::Union;
- let mut derives = vec![];
- if item.can_derive_debug(ctx) {
- derives.push("Debug");
- } else {
- needs_debug_impl = ctx.options().derive_debug &&
- ctx.options().impl_debug
- }
-
- if item.can_derive_default(ctx) {
- derives.push("Default");
- } else {
- needs_default_impl = ctx.options().derive_default;
- }
-
- if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() &&
- ctx.options().derive_copy
- {
- derives.push("Copy");
- if used_template_params.is_some() {
- // FIXME: This requires extra logic if you have a big array in a
- // templated struct. The reason for this is that the magic:
- // fn clone(&self) -> Self { *self }
- // doesn't work for templates.
- //
- // It's not hard to fix though.
- derives.push("Clone");
- } else {
- needs_clone_impl = true;
- }
- }
-
- if item.can_derive_hash(ctx) {
- derives.push("Hash");
- }
-
- if item.can_derive_partialeq(ctx) {
- derives.push("PartialEq");
- }
-
- if item.can_derive_eq(ctx) {
- derives.push("Eq");
- }
-
- if !derives.is_empty() {
- attributes.push(attributes::derives(&derives))
- }
-
let canonical_name = item.canonical_name(ctx);
let canonical_ident = ctx.rust_ident(&canonical_name);
- let mut tokens = if is_union && self.can_be_rust_union(ctx) {
- quote! {
- #( #attributes )*
- pub union #canonical_ident
- }
- } else {
- quote! {
- #( #attributes )*
- pub struct #canonical_ident
- }
- };
// Generate the vtable from the method list if appropriate.
//
@@ -1523,7 +1424,7 @@ impl CodeGenerator for CompInfo {
//
// FIXME: Once we generate proper vtables, we need to codegen the
// vtable, but *not* generate a field for it in the case that
- // needs_explicit_vtable is false but has_vtable is true.
+ // HasVtable::has_vtable_ptr is false but HasVtable::has_vtable is true.
//
// Also, we need to generate the vtable in such a way it "inherits" from
// the parent too.
@@ -1533,7 +1434,7 @@ impl CodeGenerator for CompInfo {
StructLayoutTracker::new(ctx, self, &canonical_name);
if !is_opaque {
- if self.needs_explicit_vtable(ctx, item) {
+ if item.has_vtable_ptr(ctx) {
let vtable =
Vtable::new(item.id(), self.methods(), self.base_members());
vtable.codegen(ctx, result, item);
@@ -1550,30 +1451,15 @@ impl CodeGenerator for CompInfo {
struct_layout.saw_vtable();
}
- for (i, base) in self.base_members().iter().enumerate() {
- // Virtual bases are already taken into account by the vtable
- // pointer.
- //
- // FIXME(emilio): Is this always right?
- if base.is_virtual() {
- continue;
- }
-
- let base_ty = ctx.resolve_type(base.ty);
- // NB: We won't include unsized types in our base chain because they
- // would contribute to our size given the dummy field we insert for
- // unsized types.
- if base_ty.is_unsized(ctx, &base.ty) {
+ for base in self.base_members() {
+ if !base.requires_storage(ctx) {
continue;
}
let inner = base.ty.to_rust_ty_or_opaque(ctx, &());
- let field_name = ctx.rust_ident(if i == 0 {
- "_base".into()
- } else {
- format!("_base_{}", i)
- });
+ let field_name = ctx.rust_ident(&base.field_name);
+ let base_ty = ctx.resolve_type(base.ty);
struct_layout.saw_base(base_ty);
fields.push(quote! {
@@ -1581,6 +1467,8 @@ impl CodeGenerator for CompInfo {
});
}
}
+
+ let is_union = self.kind() == CompKind::Union;
if is_union {
result.saw_union();
if !self.can_be_rust_union(ctx) {
@@ -1590,7 +1478,6 @@ impl CodeGenerator for CompInfo {
let mut methods = vec![];
if !is_opaque {
- let mut anon_field_names = AnonFieldNames::default();
let codegen_depth = item.codegen_depth(ctx);
let fields_should_be_private =
item.annotations().private_fields().unwrap_or(false);
@@ -1604,7 +1491,6 @@ impl CodeGenerator for CompInfo {
codegen_depth,
struct_accessor_kind,
self,
- &mut anon_field_names,
result,
&mut struct_layout,
&mut fields,
@@ -1648,17 +1534,24 @@ impl CodeGenerator for CompInfo {
warn!("Opaque type without layout! Expect dragons!");
}
}
- } else if !is_union && !self.is_unsized(ctx, &item.id()) {
+ } else if !is_union && !item.is_zero_sized(ctx) {
if let Some(padding_field) =
layout.and_then(|layout| struct_layout.pad_struct(layout))
{
fields.push(padding_field);
}
- if let Some(align_field) =
- layout.and_then(|layout| struct_layout.align_struct(layout))
- {
- fields.push(align_field);
+ if let Some(layout) = layout {
+ if struct_layout.requires_explicit_align(layout) {
+ if layout.align == 1 {
+ packed = true;
+ } else {
+ let ty = helpers::blob(Layout::new(0, layout.align));
+ fields.push(quote! {
+ pub __bindgen_align: #ty ,
+ });
+ }
+ }
}
}
@@ -1672,7 +1565,7 @@ impl CodeGenerator for CompInfo {
//
// NOTE: This check is conveniently here to avoid the dummy fields we
// may add for unused template parameters.
- if self.is_unsized(ctx, &item.id()) {
+ if item.is_zero_sized(ctx) {
let has_address = if is_opaque {
// Generate the address field if it's an opaque type and
// couldn't determine the layout of the blob.
@@ -1689,33 +1582,126 @@ impl CodeGenerator for CompInfo {
}
}
- let mut generics = quote! {};
+ let mut generic_param_names = vec![];
if let Some(ref params) = used_template_params {
- if !params.is_empty() {
- let mut param_names = vec![];
+ for (idx, ty) in params.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());
- for (idx, ty) in params.iter().enumerate() {
- let param = ctx.resolve_type(*ty);
- let name = param.name().unwrap();
- let ident = ctx.rust_ident(name);
- 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 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! { }
+ };
- generics = quote! {
- < #( #param_names ),* >
- };
+ 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;
+ if let Some(comment) = item.comment(ctx) {
+ attributes.push(attributes::doc(comment));
+ }
+ if packed {
+ attributes.push(attributes::repr_list(&["C", "packed"]));
+ } else {
+ attributes.push(attributes::repr("C"));
+ }
+
+ let mut derives = vec![];
+ if item.can_derive_debug(ctx) {
+ derives.push("Debug");
+ } else {
+ needs_debug_impl = ctx.options().derive_debug &&
+ ctx.options().impl_debug
+ }
+
+ if item.can_derive_default(ctx) {
+ derives.push("Default");
+ } else {
+ needs_default_impl = ctx.options().derive_default;
+ }
+
+ if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() &&
+ ctx.options().derive_copy
+ {
+ derives.push("Copy");
+
+ if ctx.options().rust_features().builtin_clone_impls() ||
+ used_template_params.is_some()
+ {
+ // FIXME: This requires extra logic if you have a big array in a
+ // templated struct. The reason for this is that the magic:
+ // fn clone(&self) -> Self { *self }
+ // doesn't work for templates.
+ //
+ // It's not hard to fix though.
+ derives.push("Clone");
+ } else {
+ needs_clone_impl = true;
}
}
+ if item.can_derive_hash(ctx) {
+ derives.push("Hash");
+ }
+
+ if item.can_derive_partialord(ctx) {
+ derives.push("PartialOrd");
+ }
+
+ if item.can_derive_ord(ctx) {
+ derives.push("Ord");
+ }
+
+ if item.can_derive_partialeq(ctx) {
+ derives.push("PartialEq");
+ } else {
+ needs_partialeq_impl =
+ ctx.options().derive_partialeq &&
+ ctx.options().impl_partialeq &&
+ ctx.lookup_can_derive_partialeq_or_partialord(item.id())
+ .map_or(true, |x| {
+ x == CannotDeriveReason::ArrayTooLarge
+ });
+ }
+
+ if item.can_derive_eq(ctx) {
+ derives.push("Eq");
+ }
+
+ if !derives.is_empty() {
+ attributes.push(attributes::derives(&derives))
+ }
+
+ let mut tokens = if is_union && self.can_be_rust_union(ctx) {
+ quote! {
+ #( #attributes )*
+ pub union #canonical_ident
+ }
+ } else {
+ quote! {
+ #( #attributes )*
+ pub struct #canonical_ident
+ }
+ };
+
tokens.append(quote! {
#generics {
#( #fields )*
@@ -1781,9 +1767,8 @@ impl CodeGenerator for CompInfo {
// FIXME when [issue #465](https://github.com/rust-lang-nursery/rust-bindgen/issues/465) ready
let too_many_base_vtables = self.base_members()
.iter()
- .filter(|base| ctx.lookup_item_id_has_vtable(&base.ty))
- .count() >
- 1;
+ .filter(|base| base.ty.has_vtable(ctx))
+ .count() > 1;
let should_skip_field_offset_checks = is_opaque ||
too_many_base_vtables;
@@ -1905,7 +1890,7 @@ impl CodeGenerator for CompInfo {
}
if needs_debug_impl {
- let impl_ = derive_debug::gen_debug_impl(
+ let impl_ = impl_debug::gen_debug_impl(
ctx,
self.fields(),
item,
@@ -1919,6 +1904,27 @@ impl CodeGenerator for CompInfo {
});
}
+ if needs_partialeq_impl {
+ if let Some(impl_) = impl_partialeq::gen_partialeq_impl(ctx, self, item, &ty_for_impl) {
+
+ let partialeq_bounds = if !generic_param_names.is_empty() {
+ let bounds = generic_param_names.iter().map(|t| {
+ quote! { #t: PartialEq }
+ });
+ quote! { where #( #bounds ),* }
+ } else {
+ quote! { }
+ };
+
+ let prefix = ctx.trait_prefix();
+ result.push(quote! {
+ impl #generics ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds {
+ #impl_
+ }
+ });
+ }
+ }
+
if !methods.is_empty() {
result.push(quote! {
impl #generics #ty_for_impl {
@@ -1981,6 +1987,10 @@ impl MethodCodegen for Method {
_ => panic!("How in the world?"),
};
+ if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi()) {
+ return;
+ }
+
// Do not generate variadic methods, since rust does not allow
// implementing them, and we don't do a good job at it anyway.
if signature.is_variadic() {
@@ -2449,7 +2459,10 @@ impl CodeGenerator for Enum {
let repr =
self.repr()
.and_then(|repr| repr.try_to_rust_ty_or_opaque(ctx, &()).ok())
- .unwrap_or_else(|| helpers::ast_ty::raw_type(ctx, repr_name));
+ .unwrap_or_else(|| {
+ let repr_name = ctx.rust_ident_raw(repr_name);
+ quote! { #repr_name }
+ });
let mut builder = EnumBuilder::new(
&name,
@@ -2748,7 +2761,10 @@ where
}
}
-impl TryToOpaque for ItemId {
+impl<T> TryToOpaque for T
+where
+ T: Copy + Into<ItemId>
+{
type Extra = ();
fn try_get_layout(
@@ -2756,11 +2772,14 @@ impl TryToOpaque for ItemId {
ctx: &BindgenContext,
_: &(),
) -> error::Result<Layout> {
- ctx.resolve_item(*self).try_get_layout(ctx, &())
+ ctx.resolve_item((*self).into()).try_get_layout(ctx, &())
}
}
-impl TryToRustTy for ItemId {
+impl<T> TryToRustTy for T
+where
+ T: Copy + Into<ItemId>
+{
type Extra = ();
fn try_to_rust_ty(
@@ -2768,7 +2787,7 @@ impl TryToRustTy for ItemId {
ctx: &BindgenContext,
_: &(),
) -> error::Result<quote::Tokens> {
- ctx.resolve_item(*self).try_to_rust_ty(ctx, &())
+ ctx.resolve_item((*self).into()).try_to_rust_ty(ctx, &())
}
}
@@ -2909,8 +2928,8 @@ impl TryToRustTy for Type {
inst.try_to_rust_ty(ctx, item)
}
TypeKind::ResolvedTypeRef(inner) => inner.try_to_rust_ty(ctx, &()),
- TypeKind::TemplateAlias(inner, _) |
- TypeKind::Alias(inner) => {
+ TypeKind::TemplateAlias(..) |
+ TypeKind::Alias(..) => {
let template_params = item.used_template_params(ctx)
.unwrap_or(vec![])
.into_iter()
@@ -2923,12 +2942,11 @@ impl TryToRustTy for Type {
} else if let Some(ty) = utils::type_from_named(
ctx,
spelling,
- inner,
)
{
Ok(ty)
} else {
- utils::build_templated_path(item, ctx, vec![]) //template_params)
+ utils::build_path(item, ctx)
}
}
TypeKind::Comp(ref info) => {
@@ -2939,8 +2957,7 @@ impl TryToRustTy for Type {
return self.try_to_opaque(ctx, item);
}
- // let template_params = template_params.unwrap_or(vec![]);
- utils::build_templated_path(item, ctx, vec![])
+ utils::build_path(item, ctx)
}
TypeKind::Opaque => self.try_to_opaque(ctx, item),
TypeKind::BlockPointer => {
@@ -3087,9 +3104,17 @@ impl TryToRustTy for FunctionSig {
let arguments = utils::fnsig_arguments(ctx, &self);
let abi = self.abi();
- Ok(quote! {
- unsafe extern #abi fn ( #( #arguments ),* ) #ret
- })
+ match abi {
+ Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
+ warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
+ Ok(quote::Tokens::new())
+ }
+ _ => {
+ Ok(quote! {
+ unsafe extern #abi fn ( #( #arguments ),* ) #ret
+ })
+ }
+ }
}
}
@@ -3105,6 +3130,13 @@ impl CodeGenerator for Function {
debug!("<Function as CodeGenerator>::codegen: item = {:?}", item);
debug_assert!(item.is_enabled_for_codegen(ctx));
+ // We can't currently do anything with Internal functions so just
+ // avoid generating anything for them.
+ match self.linkage() {
+ Linkage::Internal => return,
+ Linkage::External => {}
+ }
+
// Similar to static member variables in a class template, we can't
// generate bindings to template functions, because the set of
// instantiations is open ended and we have no way of knowing which
@@ -3161,6 +3193,10 @@ impl CodeGenerator for Function {
}
let abi = match signature.abi() {
+ Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
+ warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
+ return;
+ }
Abi::Unknown(unknown_abi) => {
panic!(
"Invalid or unknown abi {:?} for function {:?} ({:?})",
@@ -3315,7 +3351,7 @@ impl CodeGenerator for ObjCInterface {
}
}
-pub fn codegen(context: &mut BindgenContext) -> Vec<quote::Tokens> {
+pub(crate) fn codegen(context: BindgenContext) -> (Vec<quote::Tokens>, BindgenOptions) {
context.gen(|context| {
let _t = context.timer("codegen");
let counter = Cell::new(0);
@@ -3346,8 +3382,8 @@ pub fn codegen(context: &mut BindgenContext) -> Vec<quote::Tokens> {
}
mod utils {
- use super::{ToRustTyOrOpaque, TryToRustTy, error};
- use ir::context::{BindgenContext, ItemId};
+ use super::{ToRustTyOrOpaque, error};
+ use ir::context::BindgenContext;
use ir::function::FunctionSig;
use ir::item::{Item, ItemCanonicalPath};
use ir::ty::TypeKind;
@@ -3569,28 +3605,16 @@ mod utils {
result.extend(old_items.into_iter());
}
- pub fn build_templated_path(
+ pub fn build_path(
item: &Item,
ctx: &BindgenContext,
- template_params: Vec<ItemId>,
) -> error::Result<quote::Tokens> {
let path = item.namespace_aware_canonical_path(ctx);
- let template_params = template_params
- .iter()
- .map(|param| param.try_to_rust_ty(ctx, &()))
- .collect::<error::Result<Vec<_>>>()?;
-
let mut tokens = quote! {};
tokens.append_separated(path.into_iter().map(quote::Ident::new), "::");
- if template_params.is_empty() {
- Ok(tokens)
- } else {
- Ok(quote! {
- #tokens < #( #template_params ),* >
- })
- }
+ Ok(tokens)
}
fn primitive_ty(ctx: &BindgenContext, name: &str) -> quote::Tokens {
@@ -3603,7 +3627,6 @@ mod utils {
pub fn type_from_named(
ctx: &BindgenContext,
name: &str,
- _inner: ItemId,
) -> Option<quote::Tokens> {
// FIXME: We could use the inner item to check this is really a
// primitive type but, who the heck overrides these anyway?
diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs
index 06059853..c3c781cb 100644
--- a/src/codegen/struct_layout.rs
+++ b/src/codegen/struct_layout.rs
@@ -288,18 +288,9 @@ impl<'a> StructLayoutTracker<'a> {
}
}
- pub fn align_struct(&self, layout: Layout) -> Option<quote::Tokens> {
- if self.max_field_align < layout.align &&
+ pub fn requires_explicit_align(&self, layout: Layout) -> bool {
+ self.max_field_align < layout.align &&
layout.align <= mem::size_of::<*mut ()>()
- {
- let ty = helpers::blob(Layout::new(0, layout.align));
-
- Some(quote! {
- pub __bindgen_align: #ty ,
- })
- } else {
- None
- }
}
fn padding_bytes(&self, layout: Layout) -> usize {
diff --git a/src/features.rs b/src/features.rs
index 29e60ab7..0954d87b 100644
--- a/src/features.rs
+++ b/src/features.rs
@@ -90,6 +90,8 @@ macro_rules! rust_target_base {
=> Stable_1_0 => 1.0;
/// Rust stable 1.19
=> Stable_1_19 => 1.19;
+ /// Rust stable 1.21
+ => Stable_1_21 => 1.21;
/// Nightly rust
=> Nightly => nightly;
);
@@ -100,7 +102,7 @@ rust_target_base!(rust_target_def);
rust_target_base!(rust_target_values_def);
/// Latest stable release of Rust
-pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_19;
+pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_21;
/// Create RustFeatures struct definition, new(), and a getter for each field
macro_rules! rust_feature_def {
@@ -140,6 +142,10 @@ rust_feature_def!(
=> untagged_union;
/// Constant function ([RFC 911](https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md))
=> const_fn;
+ /// `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
+ => thiscall_abi;
+ /// builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690))
+ => builtin_clone_impls;
);
impl From<RustTarget> for RustFeatures {
@@ -150,8 +156,13 @@ impl From<RustTarget> for RustFeatures {
features.untagged_union = true;
}
+ if rust_target >= RustTarget::Stable_1_21 {
+ features.builtin_clone_impls = true;
+ }
+
if rust_target >= RustTarget::Nightly {
features.const_fn = true;
+ features.thiscall_abi = true;
}
features
@@ -180,6 +191,7 @@ mod test {
fn str_to_target() {
test_target("1.0", RustTarget::Stable_1_0);
test_target("1.19", RustTarget::Stable_1_19);
+ test_target("1.21", RustTarget::Stable_1_21);
test_target("nightly", RustTarget::Nightly);
}
}
diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs
index ef01c65a..8da47a7f 100644
--- a/src/ir/analysis/derive_copy.rs
+++ b/src/ir/analysis/derive_copy.rs
@@ -9,6 +9,7 @@ use ir::derive::CanTriviallyDeriveCopy;
use ir::item::IsOpaque;
use ir::template::TemplateParameters;
use ir::traversal::EdgeKind;
+use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
use ir::ty::TypeKind;
use std::collections::HashMap;
use std::collections::HashSet;
@@ -72,7 +73,8 @@ impl<'ctx> CannotDeriveCopy<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_copy set", id);
let was_not_already_in_set = self.cannot_derive_copy.insert(id);
@@ -88,7 +90,8 @@ impl<'ctx> CannotDeriveCopy<'ctx> {
/// A type is not `Copy` if we've determined it is not copy, or if it is
/// blacklisted.
- fn is_not_copy(&self, id: ItemId) -> bool {
+ fn is_not_copy<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
self.cannot_derive_copy.contains(&id) ||
!self.ctx.whitelisted_items().contains(&id)
}
@@ -140,6 +143,10 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
}
};
+ if self.ctx.no_copy_by_name(&item) {
+ return self.insert(id);
+ }
+
if item.is_opaque(self.ctx, &()) {
let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| {
l.opaque().can_trivially_derive_copy()
@@ -221,7 +228,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
// NOTE: Take into account that while unions in C and C++ are copied by
// default, the may have an explicit destructor in C++, so we can't
// defer this check just for the union case.
- if self.ctx.lookup_item_id_has_destructor(&id) {
+ if self.ctx.lookup_has_destructor(id.expect_type_id(self.ctx)) {
trace!(" comp has destructor which cannot derive copy");
return self.insert(id);
}
@@ -266,6 +273,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
self.is_not_copy(data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Copy for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
self.is_not_copy(b.ty())
})
@@ -298,7 +313,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
"The early ty.is_opaque check should have handled this case"
);
let def_cannot_derive = self.is_not_copy(
- template.template_definition(),
+ template.template_definition()
);
if def_cannot_derive {
trace!(
diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs
index 2bfaff71..a1743ae9 100644
--- a/src/ir/analysis/derive_debug.rs
+++ b/src/ir/analysis/derive_debug.rs
@@ -74,7 +74,8 @@ impl<'ctx> CannotDeriveDebug<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_debug set", id);
let was_not_already_in_set = self.cannot_derive_debug.insert(id);
@@ -90,7 +91,8 @@ impl<'ctx> CannotDeriveDebug<'ctx> {
/// A type is not `Debug` if we've determined it is not debug, or if it is
/// blacklisted.
- fn is_not_debug(&self, id: ItemId) -> bool {
+ fn is_not_debug<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
self.cannot_derive_debug.contains(&id) ||
!self.ctx.whitelisted_items().contains(&id)
}
@@ -268,6 +270,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
self.is_not_debug(data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Debug for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
self.is_not_debug(b.ty())
})
@@ -317,7 +327,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
"The early ty.is_opaque check should have handled this case"
);
let def_cannot_derive = self.is_not_debug(
- template.template_definition(),
+ template.template_definition()
);
if def_cannot_derive {
trace!(
diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs
index 96805863..f8f02df7 100644
--- a/src/ir/analysis/derive_default.rs
+++ b/src/ir/analysis/derive_default.rs
@@ -71,7 +71,8 @@ impl<'ctx> CannotDeriveDefault<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_default set", id);
let was_not_already_in_set = self.cannot_derive_default.insert(id);
@@ -85,7 +86,8 @@ impl<'ctx> CannotDeriveDefault<'ctx> {
ConstrainResult::Changed
}
- fn is_not_default(&self, id: ItemId) -> bool {
+ fn is_not_default<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
self.cannot_derive_default.contains(&id) ||
!self.ctx.whitelisted_items().contains(&id)
}
@@ -288,7 +290,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
let bases_cannot_derive =
info.base_members().iter().any(|base| {
- !self.ctx.whitelisted_items().contains(&base.ty) ||
+ !self.ctx.whitelisted_items().contains(&base.ty.into()) ||
self.is_not_default(base.ty)
});
if bases_cannot_derive {
@@ -303,14 +305,22 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
info.fields().iter().any(|f| match *f {
Field::DataMember(ref data) => {
!self.ctx.whitelisted_items().contains(
- &data.ty(),
+ &data.ty().into(),
) ||
self.is_not_default(data.ty())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Default for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
- &b.ty(),
+ &b.ty().into(),
) ||
self.is_not_default(b.ty())
})
diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs
index 80ea0abf..46790232 100644
--- a/src/ir/analysis/derive_hash.rs
+++ b/src/ir/analysis/derive_hash.rs
@@ -74,7 +74,8 @@ impl<'ctx> CannotDeriveHash<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_hash set", id);
let was_not_already_in_set = self.cannot_derive_hash.insert(id);
@@ -126,6 +127,10 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
}
};
+ if self.ctx.no_hash_by_name(&item) {
+ return self.insert(id)
+ }
+
if item.is_opaque(self.ctx, &()) {
let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| {
l.opaque().can_trivially_derive_hash()
@@ -178,7 +183,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
}
TypeKind::Array(t, len) => {
- if self.cannot_derive_hash.contains(&t) {
+ if self.cannot_derive_hash.contains(&t.into()) {
trace!(
" arrays of T for which we cannot derive Hash \
also cannot derive Hash"
@@ -186,7 +191,10 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
return self.insert(id);
}
- if len <= RUST_DERIVE_IN_ARRAY_LIMIT {
+ if len == 0 {
+ trace!(" cannot derive `Hash` for incomplete arrays");
+ self.insert(id)
+ } else if len <= RUST_DERIVE_IN_ARRAY_LIMIT {
trace!(" array is small enough to derive Hash");
ConstrainResult::Same
} else {
@@ -222,7 +230,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
- if self.cannot_derive_hash.contains(&t) {
+ if self.cannot_derive_hash.contains(&t.into()) {
trace!(
" aliases and type refs to T which cannot derive \
Hash also cannot derive Hash"
@@ -263,8 +271,8 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
let bases_cannot_derive =
info.base_members().iter().any(|base| {
- !self.ctx.whitelisted_items().contains(&base.ty) ||
- self.cannot_derive_hash.contains(&base.ty)
+ !self.ctx.whitelisted_items().contains(&base.ty.into()) ||
+ self.cannot_derive_hash.contains(&base.ty.into())
});
if bases_cannot_derive {
trace!(
@@ -278,16 +286,24 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
info.fields().iter().any(|f| match *f {
Field::DataMember(ref data) => {
!self.ctx.whitelisted_items().contains(
- &data.ty(),
+ &data.ty().into(),
) ||
- self.cannot_derive_hash.contains(&data.ty())
+ self.cannot_derive_hash.contains(&data.ty().into())
}
Field::Bitfields(ref bfu) => {
+ if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " we cannot derive Hash for a bitfield larger then \
+ the limit"
+ );
+ return true;
+ }
+
bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
- &b.ty(),
+ &b.ty().into(),
) ||
- self.cannot_derive_hash.contains(&b.ty())
+ self.cannot_derive_hash.contains(&b.ty().into())
})
}
});
@@ -303,7 +319,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
TypeKind::TemplateInstantiation(ref template) => {
let args_cannot_derive =
template.template_arguments().iter().any(|arg| {
- self.cannot_derive_hash.contains(&arg)
+ self.cannot_derive_hash.contains(&arg.into())
});
if args_cannot_derive {
trace!(
@@ -318,7 +334,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
"The early ty.is_opaque check should have handled this case"
);
let def_cannot_derive = self.cannot_derive_hash.contains(
- &template.template_definition(),
+ &template.template_definition().into(),
);
if def_cannot_derive {
trace!(
diff --git a/src/ir/analysis/derive_partial_eq.rs b/src/ir/analysis/derive_partial_eq.rs
deleted file mode 100644
index 96689601..00000000
--- a/src/ir/analysis/derive_partial_eq.rs
+++ /dev/null
@@ -1,369 +0,0 @@
-//! Determining which types for which we can emit `#[derive(PartialEq)]`.
-
-use super::{ConstrainResult, MonotoneFramework, generate_dependencies};
-use ir::comp::CompKind;
-use ir::comp::Field;
-use ir::comp::FieldMethods;
-use ir::context::{BindgenContext, ItemId};
-use ir::derive::CanTriviallyDerivePartialEq;
-use ir::item::IsOpaque;
-use ir::traversal::EdgeKind;
-use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
-use ir::ty::TypeKind;
-use std::collections::HashMap;
-use std::collections::HashSet;
-
-/// An analysis that finds for each IR item whether partialeq cannot be derived.
-///
-/// We use the monotone constraint function `cannot_derive_partial_eq`, defined as
-/// follows:
-///
-/// * If T is Opaque and layout of the type is known, get this layout as opaque
-/// type and check whether it can be derived using trivial checks.
-/// * If T is Array type, partialeq cannot be derived if the length of the array is
-/// larger than the limit or the type of data the array contains cannot derive
-/// partialeq.
-/// * If T is a type alias, a templated alias or an indirection to another type,
-/// partialeq cannot be derived if the type T refers to cannot be derived partialeq.
-/// * If T is a compound type, partialeq cannot be derived if any of its base member
-/// or field cannot be derived partialeq.
-/// * If T is a pointer, T cannot be derived partialeq if T is a function pointer
-/// and the function signature cannot be derived partialeq.
-/// * If T is an instantiation of an abstract template definition, T cannot be
-/// derived partialeq if any of the template arguments or template definition
-/// cannot derive partialeq.
-#[derive(Debug, Clone)]
-pub struct CannotDerivePartialEq<'ctx> {
- ctx: &'ctx BindgenContext,
-
- // The incremental result of this analysis's computation. Everything in this
- // set cannot derive partialeq.
- cannot_derive_partialeq: HashSet<ItemId>,
-
- // Dependencies saying that if a key ItemId has been inserted into the
- // `cannot_derive_partialeq` set, then each of the ids in Vec<ItemId> need to be
- // considered again.
- //
- // This is a subset of the natural IR graph with reversed edges, where we
- // only include the edges from the IR graph that can affect whether a type
- // can derive partialeq or not.
- dependencies: HashMap<ItemId, Vec<ItemId>>,
-}
-
-impl<'ctx> CannotDerivePartialEq<'ctx> {
- fn consider_edge(kind: EdgeKind) -> bool {
- match kind {
- // These are the only edges that can affect whether a type can derive
- // partialeq or not.
- EdgeKind::BaseMember |
- EdgeKind::Field |
- EdgeKind::TypeReference |
- EdgeKind::VarType |
- EdgeKind::TemplateArgument |
- EdgeKind::TemplateDeclaration |
- EdgeKind::TemplateParameterDefinition => true,
-
- EdgeKind::Constructor |
- EdgeKind::Destructor |
- EdgeKind::FunctionReturn |
- EdgeKind::FunctionParameter |
- EdgeKind::InnerType |
- EdgeKind::InnerVar |
- EdgeKind::Method => false,
- EdgeKind::Generic => false,
- }
- }
-
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
- trace!("inserting {:?} into the cannot_derive_partialeq set", id);
-
- let was_not_already_in_set = self.cannot_derive_partialeq.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
- );
-
- ConstrainResult::Changed
- }
-}
-
-impl<'ctx> MonotoneFramework for CannotDerivePartialEq<'ctx> {
- type Node = ItemId;
- type Extra = &'ctx BindgenContext;
- type Output = HashSet<ItemId>;
-
- fn new(
- ctx: &'ctx BindgenContext,
- ) -> CannotDerivePartialEq<'ctx> {
- let cannot_derive_partialeq = HashSet::new();
- let dependencies = generate_dependencies(ctx, Self::consider_edge);
-
- CannotDerivePartialEq {
- ctx,
- cannot_derive_partialeq,
- dependencies,
- }
- }
-
- fn initial_worklist(&self) -> Vec<ItemId> {
- self.ctx.whitelisted_items().iter().cloned().collect()
- }
-
- fn constrain(&mut self, id: ItemId) -> ConstrainResult {
- trace!("constrain: {:?}", id);
-
- if self.cannot_derive_partialeq.contains(&id) {
- trace!(" already know it cannot derive PartialEq");
- return ConstrainResult::Same;
- }
-
- 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;
- }
- };
-
- trace!("ty: {:?}", ty);
- if item.is_opaque(self.ctx, &()) {
- let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| {
- l.opaque().can_trivially_derive_partialeq()
- });
- return if layout_can_derive &&
- !(ty.is_union() &&
- self.ctx.options().rust_features().untagged_union()) {
- trace!(" we can trivially derive PartialEq for the layout");
- ConstrainResult::Same
- } else {
- trace!(" we cannot derive PartialEq for the layout");
- self.insert(id)
- };
- }
-
- if ty.layout(self.ctx).map_or(false, |l| {
- l.align > RUST_DERIVE_IN_ARRAY_LIMIT
- })
- {
- // We have to be conservative: the struct *could* have enough
- // padding that we emit an array that is longer than
- // `RUST_DERIVE_IN_ARRAY_LIMIT`. If we moved padding calculations
- // into the IR and computed them before this analysis, then we could
- // be precise rather than conservative here.
- return self.insert(id);
- }
-
- match *ty.kind() {
- // Handle the simple cases. These can derive partialeq without further
- // information.
- TypeKind::Void |
- TypeKind::NullPtr |
- TypeKind::Int(..) |
- TypeKind::Complex(..) |
- TypeKind::Float(..) |
- TypeKind::Enum(..) |
- TypeKind::TypeParam |
- TypeKind::UnresolvedTypeRef(..) |
- TypeKind::BlockPointer |
- TypeKind::Reference(..) |
- TypeKind::ObjCInterface(..) |
- TypeKind::ObjCId |
- TypeKind::ObjCSel => {
- trace!(" simple type that can always derive PartialEq");
- ConstrainResult::Same
- }
-
- TypeKind::Array(t, len) => {
- if self.cannot_derive_partialeq.contains(&t) {
- trace!(
- " arrays of T for which we cannot derive PartialEq \
- also cannot derive PartialEq"
- );
- return self.insert(id);
- }
-
- if len <= RUST_DERIVE_IN_ARRAY_LIMIT {
- trace!(" array is small enough to derive PartialEq");
- ConstrainResult::Same
- } else {
- trace!(" array is too large to derive PartialEq");
- self.insert(id)
- }
- }
-
- TypeKind::Pointer(inner) => {
- let inner_type =
- self.ctx.resolve_type(inner).canonical_type(self.ctx);
- if let TypeKind::Function(ref sig) = *inner_type.kind() {
- if !sig.can_trivially_derive_partialeq() {
- trace!(
- " function pointer that can't trivially derive PartialEq"
- );
- return self.insert(id);
- }
- }
- trace!(" pointers can derive PartialEq");
- ConstrainResult::Same
- }
-
- TypeKind::Function(ref sig) => {
- if !sig.can_trivially_derive_partialeq() {
- trace!(
- " function that can't trivially derive PartialEq"
- );
- return self.insert(id);
- }
- trace!(" function can derive PartialEq");
- ConstrainResult::Same
- }
-
- TypeKind::ResolvedTypeRef(t) |
- TypeKind::TemplateAlias(t, _) |
- TypeKind::Alias(t) => {
- if self.cannot_derive_partialeq.contains(&t) {
- trace!(
- " aliases and type refs to T which cannot derive \
- PartialEq also cannot derive PartialEq"
- );
- self.insert(id)
- } else {
- trace!(
- " aliases and type refs to T which can derive \
- PartialEq can also derive PartialEq"
- );
- ConstrainResult::Same
- }
- }
-
- TypeKind::Comp(ref info) => {
- assert!(
- !info.has_non_type_template_params(),
- "The early ty.is_opaque check should have handled this case"
- );
-
- if info.kind() == CompKind::Union {
- if self.ctx.options().rust_features().untagged_union() {
- trace!(" cannot derive PartialEq for Rust unions");
- return self.insert(id);
- }
-
- if ty.layout(self.ctx).map_or(true, |l| {
- l.opaque().can_trivially_derive_partialeq()
- })
- {
- trace!(
- " union layout can trivially derive PartialEq"
- );
- return ConstrainResult::Same;
- } else {
- trace!(" union layout cannot derive PartialEq");
- return self.insert(id);
- }
- }
-
- let bases_cannot_derive =
- info.base_members().iter().any(|base| {
- !self.ctx.whitelisted_items().contains(&base.ty) ||
- self.cannot_derive_partialeq.contains(&base.ty)
- });
- if bases_cannot_derive {
- trace!(
- " base members cannot derive PartialEq, so we can't \
- either"
- );
- return self.insert(id);
- }
-
- let fields_cannot_derive =
- info.fields().iter().any(|f| match *f {
- Field::DataMember(ref data) => {
- !self.ctx.whitelisted_items().contains(
- &data.ty(),
- ) ||
- self.cannot_derive_partialeq.contains(
- &data.ty(),
- )
- }
- Field::Bitfields(ref bfu) => {
- bfu.bitfields().iter().any(|b| {
- !self.ctx.whitelisted_items().contains(
- &b.ty(),
- ) ||
- self.cannot_derive_partialeq.contains(
- &b.ty(),
- )
- })
- }
- });
- if fields_cannot_derive {
- trace!(
- " fields cannot derive PartialEq, so we can't either"
- );
- return self.insert(id);
- }
-
- trace!(" comp can derive PartialEq");
- ConstrainResult::Same
- }
-
- TypeKind::TemplateInstantiation(ref template) => {
- let args_cannot_derive =
- template.template_arguments().iter().any(|arg| {
- self.cannot_derive_partialeq.contains(&arg)
- });
- if args_cannot_derive {
- trace!(
- " template args cannot derive PartialEq, so \
- insantiation can't either"
- );
- return self.insert(id);
- }
-
- assert!(
- !template.template_definition().is_opaque(self.ctx, &()),
- "The early ty.is_opaque check should have handled this case"
- );
- let def_cannot_derive = self.cannot_derive_partialeq.contains(
- &template.template_definition(),
- );
- if def_cannot_derive {
- trace!(
- " template definition cannot derive PartialEq, so \
- insantiation can't either"
- );
- return self.insert(id);
- }
-
- trace!(" template instantiation can derive PartialEq");
- ConstrainResult::Same
- }
-
- TypeKind::Opaque => {
- unreachable!(
- "The early ty.is_opaque check should have handled this case"
- )
- }
- }
- }
-
- fn each_depending_on<F>(&self, id: ItemId, mut f: F)
- where
- F: FnMut(ItemId),
- {
- if let Some(edges) = self.dependencies.get(&id) {
- for item in edges {
- trace!("enqueue {:?} into worklist", item);
- f(*item);
- }
- }
- }
-}
-
-impl<'ctx> From<CannotDerivePartialEq<'ctx>> for HashSet<ItemId> {
- fn from(analysis: CannotDerivePartialEq<'ctx>) -> Self {
- analysis.cannot_derive_partialeq
- }
-}
diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
new file mode 100644
index 00000000..f54650dd
--- /dev/null
+++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
@@ -0,0 +1,424 @@
+//! Determining which types for which we cannot emit `#[derive(PartialEq,
+//! PartialOrd)]`.
+
+use super::{ConstrainResult, MonotoneFramework, generate_dependencies};
+use ir::comp::CompKind;
+use ir::context::{BindgenContext, ItemId};
+use ir::derive::{CanTriviallyDerivePartialEqOrPartialOrd, CanDerive, CannotDeriveReason};
+use ir::item::{Item, IsOpaque};
+use ir::traversal::{EdgeKind, Trace};
+use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
+use ir::ty::{TypeKind, Type};
+use std::collections::HashMap;
+
+/// An analysis that finds for each IR item whether `PartialEq`/`PartialOrd`
+/// cannot be derived.
+///
+/// We use the monotone constraint function
+/// `cannot_derive_partialeq_or_partialord`, defined as follows:
+///
+/// * If T is Opaque and layout of the type is known, get this layout as opaque
+/// type and check whether it can be derived using trivial checks.
+///
+/// * If T is Array type, `PartialEq` or partialord cannot be derived if the array is incomplete, if the length of
+/// the array is larger than the limit, or the type of data the array contains cannot derive
+/// `PartialEq`/`PartialOrd`.
+///
+/// * If T is a type alias, a templated alias or an indirection to another type,
+/// `PartialEq`/`PartialOrd` cannot be derived if the type T refers to cannot be
+/// derived `PartialEq`/`PartialOrd`.
+///
+/// * If T is a compound type, `PartialEq`/`PartialOrd` cannot be derived if any
+/// of its base member or field cannot be derived `PartialEq`/`PartialOrd`.
+///
+/// * If T is a pointer, T cannot be derived `PartialEq`/`PartialOrd` if T is a
+/// function pointer and the function signature cannot be derived
+/// `PartialEq`/`PartialOrd`.
+///
+/// * If T is an instantiation of an abstract template definition, T cannot be
+/// derived `PartialEq`/`PartialOrd` if any of the template arguments or
+/// template definition cannot derive `PartialEq`/`PartialOrd`.
+#[derive(Debug, Clone)]
+pub struct CannotDerivePartialEqOrPartialOrd<'ctx> {
+ ctx: &'ctx BindgenContext,
+
+ // The incremental result of this analysis's computation. Everything in this
+ // set cannot derive `PartialEq`/`PartialOrd`.
+ cannot_derive_partialeq_or_partialord: HashMap<ItemId, CannotDeriveReason>,
+
+ // Dependencies saying that if a key ItemId has been inserted into the
+ // `cannot_derive_partialeq_or_partialord` set, then each of the ids
+ // in Vec<ItemId> need to be considered again.
+ //
+ // This is a subset of the natural IR graph with reversed edges, where we
+ // only include the edges from the IR graph that can affect whether a type
+ // can derive `PartialEq`/`PartialOrd`.
+ dependencies: HashMap<ItemId, Vec<ItemId>>,
+}
+
+impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> {
+ fn consider_edge(kind: EdgeKind) -> bool {
+ match kind {
+ // These are the only edges that can affect whether a type can derive
+ // `PartialEq`/`PartialOrd`.
+ EdgeKind::BaseMember |
+ EdgeKind::Field |
+ EdgeKind::TypeReference |
+ EdgeKind::VarType |
+ EdgeKind::TemplateArgument |
+ EdgeKind::TemplateDeclaration |
+ EdgeKind::TemplateParameterDefinition => true,
+
+ EdgeKind::Constructor |
+ EdgeKind::Destructor |
+ EdgeKind::FunctionReturn |
+ EdgeKind::FunctionParameter |
+ EdgeKind::InnerType |
+ EdgeKind::InnerVar |
+ EdgeKind::Method => false,
+ EdgeKind::Generic => false,
+ }
+ }
+
+ fn insert<Id: Into<ItemId>>(
+ &mut self,
+ id: Id,
+ reason: CannotDeriveReason,
+ ) -> ConstrainResult {
+ let id = id.into();
+ trace!(
+ "inserting {:?} into the cannot_derive_partialeq_or_partialord because {:?}",
+ id,
+ reason
+ );
+ let existing = self.cannot_derive_partialeq_or_partialord
+ .insert(id, reason);
+ assert!(can_supersede(existing, Some(reason)));
+ ConstrainResult::Changed
+ }
+
+ fn constrain_type(
+ &mut self,
+ item: &Item,
+ ty: &Type,
+ ) -> Option<CannotDeriveReason> {
+ if !self.ctx.whitelisted_items().contains(&item.id()) {
+ return Some(CannotDeriveReason::Other);
+ }
+
+ if self.ctx.no_partialeq_by_name(&item) {
+ return Some(CannotDeriveReason::Other);
+ }
+
+ trace!("ty: {:?}", ty);
+ if item.is_opaque(self.ctx, &()) {
+ if ty.is_union()
+ && self.ctx.options().rust_features().untagged_union()
+ {
+ trace!(
+ " cannot derive `PartialEq`/`PartialOrd` for Rust unions"
+ );
+ return Some(CannotDeriveReason::Other);
+ }
+
+ let layout_can_derive = ty.layout(self.ctx)
+ .map_or(CanDerive::Yes, |l| {
+ l.opaque().can_trivially_derive_partialeq_or_partialord()
+ });
+
+ return match layout_can_derive {
+ CanDerive::Yes => {
+ trace!(
+ " we can trivially derive `PartialEq`/`PartialOrd` for the layout"
+ );
+ None
+ }
+ CanDerive::No(reason) => {
+ trace!(
+ " we cannot derive `PartialEq`/`PartialOrd` for the layout"
+ );
+ Some(reason)
+ }
+ };
+ }
+
+ match *ty.kind() {
+ // Handle the simple cases. These can derive partialeq without further
+ // information.
+ TypeKind::Void |
+ TypeKind::NullPtr |
+ TypeKind::Int(..) |
+ TypeKind::Complex(..) |
+ TypeKind::Float(..) |
+ TypeKind::Enum(..) |
+ TypeKind::TypeParam |
+ TypeKind::UnresolvedTypeRef(..) |
+ TypeKind::BlockPointer |
+ TypeKind::Reference(..) |
+ TypeKind::ObjCInterface(..) |
+ TypeKind::ObjCId |
+ TypeKind::ObjCSel => {
+ trace!(
+ " simple type that can always derive `PartialEq`/`PartialOrd`"
+ );
+ return None;
+ }
+
+ TypeKind::Array(t, len) => {
+ if self.cannot_derive_partialeq_or_partialord.contains_key(&t.into()) {
+ trace!(
+ " arrays of T for which we cannot derive `PartialEq`/`PartialOrd` \
+ also cannot derive `PartialEq`/`PartialOrd`"
+ );
+ return Some(CannotDeriveReason::Other);
+ }
+
+ if len == 0 {
+ trace!(
+ " cannot derive `PartialEq`/`PartialOrd` for incomplete arrays"
+ );
+ return Some(CannotDeriveReason::Other);
+ } else if len <= RUST_DERIVE_IN_ARRAY_LIMIT {
+ trace!(
+ " array is small enough to derive `PartialEq`/`PartialOrd`"
+ );
+ return None;
+ } else {
+ trace!(
+ " array is too large to derive `PartialEq`/`PartialOrd`"
+ );
+ return Some(CannotDeriveReason::ArrayTooLarge);
+ }
+ }
+
+ TypeKind::Pointer(inner) => {
+ let inner_type =
+ self.ctx.resolve_type(inner).canonical_type(self.ctx);
+ if let TypeKind::Function(ref sig) = *inner_type.kind() {
+ if let CanDerive::No(_) =
+ sig.can_trivially_derive_partialeq_or_partialord()
+ {
+ trace!(
+ " function pointer that can't trivially derive `PartialEq`/`PartialOrd`"
+ );
+ return Some(CannotDeriveReason::Other);
+ }
+ }
+ trace!(" pointers can derive `PartialEq`/`PartialOrd`");
+ return None;
+ }
+
+ TypeKind::Function(ref sig) => {
+ if let CanDerive::No(_) =
+ sig.can_trivially_derive_partialeq_or_partialord()
+ {
+ trace!(
+ " function that can't trivially derive `PartialEq`/`PartialOrd`"
+ );
+ return Some(CannotDeriveReason::Other);
+ }
+ trace!(" function can derive `PartialEq`/`PartialOrd`");
+ return None;
+ }
+
+ TypeKind::Comp(ref info) => {
+ assert!(
+ !info.has_non_type_template_params(),
+ "The early ty.is_opaque check should have handled this case"
+ );
+
+ if info.kind() == CompKind::Union {
+ if self.ctx.options().rust_features().untagged_union() {
+ trace!(
+ " cannot derive `PartialEq`/`PartialOrd` for Rust unions"
+ );
+ return Some(CannotDeriveReason::Other);
+ }
+
+ let layout_can_derive = ty.layout(self.ctx).map_or(
+ CanDerive::Yes,
+ |l| {
+ l.opaque()
+ .can_trivially_derive_partialeq_or_partialord()
+ },
+ );
+ return match layout_can_derive {
+ CanDerive::Yes => {
+ trace!(
+ " union layout can trivially derive `PartialEq`/`PartialOrd`"
+ );
+ None
+ }
+ CanDerive::No(reason) => {
+ trace!(
+ " union layout cannot derive `PartialEq`/`PartialOrd`"
+ );
+ Some(reason)
+ }
+ };
+ }
+ return self.constrain_join(item);
+ }
+
+ TypeKind::ResolvedTypeRef(..) |
+ TypeKind::TemplateAlias(..) |
+ TypeKind::Alias(..) |
+ TypeKind::TemplateInstantiation(..) => {
+ return self.constrain_join(item);
+ }
+
+ TypeKind::Opaque => unreachable!(
+ "The early ty.is_opaque check should have handled this case"
+ ),
+ }
+ }
+
+ fn constrain_join(&mut self, item: &Item) -> Option<CannotDeriveReason> {
+ let mut candidate = None;
+
+ item.trace(
+ self.ctx,
+ &mut |sub_id, edge_kind| {
+ // Ignore ourselves, since union with ourself is a
+ // no-op. Ignore edges that aren't relevant to the
+ // analysis.
+ if sub_id == item.id() || !Self::consider_edge(edge_kind) {
+ return;
+ }
+
+ let reason = self.cannot_derive_partialeq_or_partialord
+ .get(&sub_id)
+ .cloned();
+
+ if can_supersede(candidate, reason) {
+ candidate = reason;
+ }
+ },
+ &(),
+ );
+
+ candidate
+ }
+}
+
+/// Check if the one reason could supersede another.
+///
+/// To keep this analysis monotone we should go only in one direction.
+/// If the abscence of the reason is at the bottom and `CannotDeriveReason::Other`
+/// is at the top, then we can only go upwards.
+///
+/// Other
+/// ^
+/// |
+/// ArrayTooLarge
+/// ^
+/// |
+/// None
+///
+fn can_supersede(from: Option<CannotDeriveReason>, to: Option<CannotDeriveReason>) -> bool {
+ fn rank(maybe_reason: Option<CannotDeriveReason>) -> usize {
+ match maybe_reason {
+ None => 0,
+ Some(CannotDeriveReason::ArrayTooLarge) => 1,
+ Some(CannotDeriveReason::Other) => 2,
+ }
+ }
+ rank(from) <= rank(to)
+}
+
+impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
+ type Node = ItemId;
+ type Extra = &'ctx BindgenContext;
+ type Output = HashMap<ItemId, CannotDeriveReason>;
+
+ fn new(
+ ctx: &'ctx BindgenContext,
+ ) -> CannotDerivePartialEqOrPartialOrd<'ctx> {
+ let cannot_derive_partialeq_or_partialord = HashMap::new();
+ let dependencies = generate_dependencies(ctx, Self::consider_edge);
+
+ CannotDerivePartialEqOrPartialOrd {
+ ctx,
+ cannot_derive_partialeq_or_partialord,
+ dependencies,
+ }
+ }
+
+ fn initial_worklist(&self) -> Vec<ItemId> {
+ // The transitive closure of all whitelisted items, including explicitly
+ // blacklisted items.
+ self.ctx
+ .whitelisted_items()
+ .iter()
+ .cloned()
+ .flat_map(|i| {
+ let mut reachable = vec![i];
+ i.trace(
+ self.ctx,
+ &mut |s, _| {
+ reachable.push(s);
+ },
+ &(),
+ );
+ reachable
+ })
+ .collect()
+ }
+
+ fn constrain(&mut self, id: ItemId) -> ConstrainResult {
+ trace!("constrain: {:?}", id);
+
+ if let Some(CannotDeriveReason::Other) =
+ self.cannot_derive_partialeq_or_partialord.get(&id).cloned()
+ {
+ trace!(" already know it cannot derive `PartialEq`/`PartialOrd`");
+ return ConstrainResult::Same;
+ }
+
+ let item = self.ctx.resolve_item(id);
+ let maybe_reason = match item.as_type() {
+ Some(ty) => {
+ self.constrain_type(item, ty).or_else(|| {
+ if ty.layout(self.ctx).map_or(false, |l| {
+ l.align > RUST_DERIVE_IN_ARRAY_LIMIT
+ })
+ {
+ // We have to be conservative: the struct *could* have enough
+ // padding that we emit an array that is longer than
+ // `RUST_DERIVE_IN_ARRAY_LIMIT`. If we moved padding calculations
+ // into the IR and computed them before this analysis, then we could
+ // be precise rather than conservative here.
+ Some(CannotDeriveReason::ArrayTooLarge)
+ } else {
+ None
+ }
+ })
+ }
+ None => self.constrain_join(item),
+ };
+
+ if let Some(reason) = maybe_reason {
+ self.insert(id, reason)
+ } else {
+ ConstrainResult::Same
+ }
+ }
+
+ fn each_depending_on<F>(&self, id: ItemId, mut f: F)
+ where
+ F: FnMut(ItemId),
+ {
+ if let Some(edges) = self.dependencies.get(&id) {
+ for item in edges {
+ trace!("enqueue {:?} into worklist", item);
+ f(*item);
+ }
+ }
+ }
+}
+
+impl<'ctx> From<CannotDerivePartialEqOrPartialOrd<'ctx>> for HashMap<ItemId, CannotDeriveReason> {
+ fn from(analysis: CannotDerivePartialEqOrPartialOrd<'ctx>) -> Self {
+ analysis.cannot_derive_partialeq_or_partialord
+ }
+}
diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs
index f6400d7d..c87b7e25 100644
--- a/src/ir/analysis/has_destructor.rs
+++ b/src/ir/analysis/has_destructor.rs
@@ -54,7 +54,8 @@ impl<'ctx> HasDestructorAnalysis<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
let was_not_already_in_set = self.have_destructor.insert(id);
assert!(
was_not_already_in_set,
@@ -103,7 +104,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) |
TypeKind::ResolvedTypeRef(t) => {
- if self.have_destructor.contains(&t) {
+ if self.have_destructor.contains(&t.into()) {
self.insert(id)
} else {
ConstrainResult::Same
@@ -120,12 +121,12 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
CompKind::Struct => {
let base_or_field_destructor =
info.base_members().iter().any(|base| {
- self.have_destructor.contains(&base.ty)
+ self.have_destructor.contains(&base.ty.into())
}) ||
info.fields().iter().any(|field| {
match *field {
Field::DataMember(ref data) =>
- self.have_destructor.contains(&data.ty()),
+ self.have_destructor.contains(&data.ty().into()),
Field::Bitfields(_) => false
}
});
@@ -140,10 +141,10 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
TypeKind::TemplateInstantiation(ref inst) => {
let definition_or_arg_destructor =
- self.have_destructor.contains(&inst.template_definition())
+ self.have_destructor.contains(&inst.template_definition().into())
||
inst.template_arguments().iter().any(|arg| {
- self.have_destructor.contains(arg)
+ self.have_destructor.contains(&arg.into())
});
if definition_or_arg_destructor {
self.insert(id)
diff --git a/src/ir/analysis/has_float.rs b/src/ir/analysis/has_float.rs
index 959a411b..193862c0 100644
--- a/src/ir/analysis/has_float.rs
+++ b/src/ir/analysis/has_float.rs
@@ -62,7 +62,8 @@ impl<'ctx> HasFloat<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the has_float set", id);
let was_not_already_in_set = self.has_float.insert(id);
@@ -140,7 +141,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
}
TypeKind::Array(t, _) => {
- if self.has_float.contains(&t) {
+ if self.has_float.contains(&t.into()) {
trace!(" Array with type T that has float also has float");
return self.insert(id)
}
@@ -151,7 +152,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
- if self.has_float.contains(&t) {
+ if self.has_float.contains(&t.into()) {
trace!(" aliases and type refs to T which have float \
also have float");
self.insert(id)
@@ -165,7 +166,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
TypeKind::Comp(ref info) => {
let bases_have = info.base_members()
.iter()
- .any(|base| self.has_float.contains(&base.ty));
+ .any(|base| self.has_float.contains(&base.ty.into()));
if bases_have {
trace!(" bases have float, so we also have");
return self.insert(id);
@@ -175,12 +176,12 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
.any(|f| {
match *f {
Field::DataMember(ref data) => {
- self.has_float.contains(&data.ty())
+ self.has_float.contains(&data.ty().into())
}
Field::Bitfields(ref bfu) => {
bfu.bitfields()
.iter().any(|b| {
- self.has_float.contains(&b.ty())
+ self.has_float.contains(&b.ty().into())
})
},
}
@@ -197,7 +198,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
TypeKind::TemplateInstantiation(ref template) => {
let args_have = template.template_arguments()
.iter()
- .any(|arg| self.has_float.contains(&arg));
+ .any(|arg| self.has_float.contains(&arg.into()));
if args_have {
trace!(" template args have float, so \
insantiation also has float");
@@ -205,7 +206,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
}
let def_has = self.has_float
- .contains(&template.template_definition());
+ .contains(&template.template_definition().into());
if def_has {
trace!(" template definition has float, so \
insantiation also has");
diff --git a/src/ir/analysis/has_type_param_in_array.rs b/src/ir/analysis/has_type_param_in_array.rs
index f21bae14..aa8d34be 100644
--- a/src/ir/analysis/has_type_param_in_array.rs
+++ b/src/ir/analysis/has_type_param_in_array.rs
@@ -64,7 +64,8 @@ impl<'ctx> HasTypeParameterInArray<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!(
"inserting {:?} into the has_type_parameter_in_array set",
id
@@ -165,7 +166,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
- if self.has_type_parameter_in_array.contains(&t) {
+ if self.has_type_parameter_in_array.contains(&t.into()) {
trace!(
" aliases and type refs to T which have array \
also have array"
@@ -182,7 +183,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
TypeKind::Comp(ref info) => {
let bases_have = info.base_members().iter().any(|base| {
- self.has_type_parameter_in_array.contains(&base.ty)
+ self.has_type_parameter_in_array.contains(&base.ty.into())
});
if bases_have {
trace!(" bases have array, so we also have");
@@ -190,7 +191,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
}
let fields_have = info.fields().iter().any(|f| match *f {
Field::DataMember(ref data) => {
- self.has_type_parameter_in_array.contains(&data.ty())
+ self.has_type_parameter_in_array.contains(&data.ty().into())
}
Field::Bitfields(..) => false,
});
@@ -206,7 +207,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
TypeKind::TemplateInstantiation(ref template) => {
let args_have =
template.template_arguments().iter().any(|arg| {
- self.has_type_parameter_in_array.contains(&arg)
+ self.has_type_parameter_in_array.contains(&arg.into())
});
if args_have {
trace!(
@@ -217,7 +218,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> {
}
let def_has = self.has_type_parameter_in_array.contains(
- &template.template_definition(),
+ &template.template_definition().into(),
);
if def_has {
trace!(
diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs
index b0d48738..f3f2a695 100644
--- a/src/ir/analysis/has_vtable.rs
+++ b/src/ir/analysis/has_vtable.rs
@@ -4,8 +4,66 @@ use super::{ConstrainResult, MonotoneFramework, generate_dependencies};
use ir::context::{BindgenContext, ItemId};
use ir::traversal::EdgeKind;
use ir::ty::TypeKind;
+use std::cmp;
use std::collections::HashMap;
-use std::collections::HashSet;
+use std::collections::hash_map::Entry;
+use std::ops;
+
+/// The result of the `HasVtableAnalysis` for an individual item.
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord)]
+pub enum HasVtableResult {
+ /// The item has a vtable, but the actual vtable pointer is in a base
+ /// member.
+ BaseHasVtable,
+
+ /// The item has a vtable and the actual vtable pointer is within this item.
+ SelfHasVtable,
+
+ /// The item does not have a vtable pointer.
+ No
+}
+
+impl Default for HasVtableResult {
+ fn default() -> Self {
+ HasVtableResult::No
+ }
+}
+
+impl cmp::PartialOrd for HasVtableResult {
+ fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
+ use self::HasVtableResult::*;
+
+ match (*self, *rhs) {
+ (x, y) if x == y => Some(cmp::Ordering::Equal),
+ (BaseHasVtable, _) => Some(cmp::Ordering::Greater),
+ (_, BaseHasVtable) => Some(cmp::Ordering::Less),
+ (SelfHasVtable, _) => Some(cmp::Ordering::Greater),
+ (_, SelfHasVtable) => Some(cmp::Ordering::Less),
+ _ => unreachable!(),
+ }
+ }
+}
+
+impl HasVtableResult {
+ /// Take the least upper bound of `self` and `rhs`.
+ pub fn join(self, rhs: Self) -> Self {
+ cmp::max(self, rhs)
+ }
+}
+
+impl ops::BitOr for HasVtableResult {
+ type Output = Self;
+
+ fn bitor(self, rhs: HasVtableResult) -> Self::Output {
+ self.join(rhs)
+ }
+}
+
+impl ops::BitOrAssign for HasVtableResult {
+ fn bitor_assign(&mut self, rhs: HasVtableResult) {
+ *self = self.join(rhs)
+ }
+}
/// An analysis that finds for each IR item whether it has vtable or not
///
@@ -23,7 +81,7 @@ pub struct HasVtableAnalysis<'ctx> {
// The incremental result of this analysis's computation. Everything in this
// set definitely has a vtable.
- have_vtable: HashSet<ItemId>,
+ have_vtable: HashMap<ItemId, HasVtableResult>,
// Dependencies saying that if a key ItemId has been inserted into the
// `have_vtable` set, then each of the ids in Vec<ItemId> need to be
@@ -47,25 +105,50 @@ impl<'ctx> HasVtableAnalysis<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
- let was_not_already_in_set = self.have_vtable.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
- );
- ConstrainResult::Changed
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id, result: HasVtableResult) -> ConstrainResult {
+ if let HasVtableResult::No = result {
+ return ConstrainResult::Same;
+ }
+
+ let id = id.into();
+ match self.have_vtable.entry(id) {
+ Entry::Occupied(mut entry) => {
+ if *entry.get() < result {
+ entry.insert(result);
+ ConstrainResult::Changed
+ } else {
+ ConstrainResult::Same
+ }
+ }
+ Entry::Vacant(entry) => {
+ entry.insert(result);
+ ConstrainResult::Changed
+ }
+ }
+ }
+
+ fn forward<Id1, Id2>(&mut self, from: Id1, to: Id2) -> ConstrainResult
+ where
+ Id1: Into<ItemId>,
+ Id2: Into<ItemId>,
+ {
+ let from = from.into();
+ let to = to.into();
+
+ match self.have_vtable.get(&from).cloned() {
+ None => ConstrainResult::Same,
+ Some(r) => self.insert(to, r),
+ }
}
}
impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
type Node = ItemId;
type Extra = &'ctx BindgenContext;
- type Output = HashSet<ItemId>;
+ type Output = HashMap<ItemId, HasVtableResult>;
fn new(ctx: &'ctx BindgenContext) -> HasVtableAnalysis<'ctx> {
- let have_vtable = HashSet::new();
+ let have_vtable = HashMap::new();
let dependencies = generate_dependencies(ctx, Self::consider_edge);
HasVtableAnalysis {
@@ -80,11 +163,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
}
fn constrain(&mut self, id: ItemId) -> ConstrainResult {
- if self.have_vtable.contains(&id) {
- // We've already computed that this type has a vtable and that can't
- // change.
- return ConstrainResult::Same;
- }
+ trace!("constrain {:?}", id);
let item = self.ctx.resolve_item(id);
let ty = match item.as_type() {
@@ -98,33 +177,32 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
TypeKind::Alias(t) |
TypeKind::ResolvedTypeRef(t) |
TypeKind::Reference(t) => {
- if self.have_vtable.contains(&t) {
- self.insert(id)
- } else {
- ConstrainResult::Same
- }
+ trace!(" aliases and references forward to their inner type");
+ self.forward(t, id)
}
TypeKind::Comp(ref info) => {
+ trace!(" comp considers its own methods and bases");
+ let mut result = HasVtableResult::No;
+
if info.has_own_virtual_method() {
- return self.insert(id);
+ trace!(" comp has its own virtual method");
+ result |= HasVtableResult::SelfHasVtable;
}
+
let bases_has_vtable = info.base_members().iter().any(|base| {
- self.have_vtable.contains(&base.ty)
+ trace!(" comp has a base with a vtable: {:?}", base);
+ self.have_vtable.contains_key(&base.ty.into())
});
if bases_has_vtable {
- self.insert(id)
- } else {
- ConstrainResult::Same
+ result |= HasVtableResult::BaseHasVtable;
}
+
+ self.insert(id, result)
}
TypeKind::TemplateInstantiation(ref inst) => {
- if self.have_vtable.contains(&inst.template_definition()) {
- self.insert(id)
- } else {
- ConstrainResult::Same
- }
+ self.forward(inst.template_definition(), id)
}
_ => ConstrainResult::Same,
@@ -144,8 +222,13 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
}
}
-impl<'ctx> From<HasVtableAnalysis<'ctx>> for HashSet<ItemId> {
+impl<'ctx> From<HasVtableAnalysis<'ctx>> for HashMap<ItemId, HasVtableResult> {
fn from(analysis: HasVtableAnalysis<'ctx>) -> Self {
+ // We let the lack of an entry mean "No" to save space.
+ extra_assert!(analysis.have_vtable.values().all(|v| {
+ *v != HasVtableResult::No
+ }));
+
analysis.have_vtable
}
}
@@ -159,4 +242,8 @@ impl<'ctx> From<HasVtableAnalysis<'ctx>> for HashSet<ItemId> {
pub trait HasVtable {
/// Return `true` if this thing has vtable, `false` otherwise.
fn has_vtable(&self, ctx: &BindgenContext) -> bool;
+
+ /// Return `true` if this thing has an actual vtable pointer in itself, as
+ /// opposed to transitively in a base member.
+ fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool;
}
diff --git a/src/ir/analysis/mod.rs b/src/ir/analysis/mod.rs
index ab19cb4f..44ca4279 100644
--- a/src/ir/analysis/mod.rs
+++ b/src/ir/analysis/mod.rs
@@ -43,8 +43,7 @@ pub use self::template_params::UsedTemplateParameters;
mod derive_debug;
pub use self::derive_debug::CannotDeriveDebug;
mod has_vtable;
-pub use self::has_vtable::HasVtable;
-pub use self::has_vtable::HasVtableAnalysis;
+pub use self::has_vtable::{HasVtable, HasVtableAnalysis, HasVtableResult};
mod has_destructor;
pub use self::has_destructor::HasDestructorAnalysis;
mod derive_default;
@@ -55,15 +54,19 @@ mod has_type_param_in_array;
pub use self::has_type_param_in_array::HasTypeParameterInArray;
mod derive_hash;
pub use self::derive_hash::CannotDeriveHash;
-mod derive_partial_eq;
-pub use self::derive_partial_eq::CannotDerivePartialEq;
+mod derive_partial_eq_or_partial_ord;
+pub use self::derive_partial_eq_or_partial_ord::CannotDerivePartialEqOrPartialOrd;
mod has_float;
pub use self::has_float::HasFloat;
+mod sizedness;
+pub use self::sizedness::{Sizedness, SizednessAnalysis, SizednessResult};
use ir::context::{BindgenContext, ItemId};
+
use ir::traversal::{EdgeKind, Trace};
use std::collections::HashMap;
use std::fmt;
+use std::ops;
/// An analysis in the monotone framework.
///
@@ -125,6 +128,7 @@ pub trait MonotoneFramework: Sized + fmt::Debug {
/// Whether an analysis's `constrain` function modified the incremental results
/// or not.
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ConstrainResult {
/// The incremental results were updated, and the fix-point computation
/// should continue.
@@ -134,6 +138,30 @@ pub enum ConstrainResult {
Same,
}
+impl Default for ConstrainResult {
+ fn default() -> Self {
+ ConstrainResult::Same
+ }
+}
+
+impl ops::BitOr for ConstrainResult {
+ type Output = Self;
+
+ fn bitor(self, rhs: ConstrainResult) -> Self::Output {
+ if self == ConstrainResult::Changed || rhs == ConstrainResult::Changed {
+ ConstrainResult::Changed
+ } else {
+ ConstrainResult::Same
+ }
+ }
+}
+
+impl ops::BitOrAssign for ConstrainResult {
+ fn bitor_assign(&mut self, rhs: ConstrainResult) {
+ *self = *self | rhs;
+ }
+}
+
/// Run an analysis in the monotone framework.
pub fn analyze<Analysis>(extra: Analysis::Extra) -> Analysis::Output
where
diff --git a/src/ir/analysis/sizedness.rs b/src/ir/analysis/sizedness.rs
new file mode 100644
index 00000000..e82c1798
--- /dev/null
+++ b/src/ir/analysis/sizedness.rs
@@ -0,0 +1,360 @@
+//! Determining the sizedness of types (as base classes and otherwise).
+
+use super::{ConstrainResult, MonotoneFramework, HasVtable, generate_dependencies};
+use ir::context::{BindgenContext, TypeId};
+use ir::item::IsOpaque;
+use ir::traversal::EdgeKind;
+use ir::ty::TypeKind;
+use std::cmp;
+use std::collections::HashMap;
+use std::collections::hash_map::Entry;
+use std::ops;
+
+/// The result of the `Sizedness` analysis for an individual item.
+///
+/// This is a chain lattice of the form:
+///
+/// ```ignore
+/// NonZeroSized
+/// |
+/// DependsOnTypeParam
+/// |
+/// ZeroSized
+/// ```
+///
+/// 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, Ord)]
+pub enum SizednessResult {
+ /// Has some size that is known to be greater than zero. That doesn't mean
+ /// it has a static size, but it is not zero sized for sure. In other words,
+ /// it might contain an incomplete array or some other dynamically sized
+ /// type.
+ NonZeroSized,
+
+ /// Whether this type is zero-sized or not depends on whether a type
+ /// parameter is zero-sized or not.
+ ///
+ /// For example, given these definitions:
+ ///
+ /// ```c++
+ /// template<class T>
+ /// class Flongo : public T {};
+ ///
+ /// class Empty {};
+ ///
+ /// class NonEmpty { int x; };
+ /// ```
+ ///
+ /// Then `Flongo<Empty>` is zero-sized, and needs an `_address` byte
+ /// inserted, while `Flongo<NonEmpty>` is *not* zero-sized, and should *not*
+ /// have an `_address` byte inserted.
+ ///
+ /// We don't properly handle this situation correctly right now:
+ /// https://github.com/rust-lang-nursery/rust-bindgen/issues/586
+ DependsOnTypeParam,
+
+ /// 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.
+ ZeroSized,
+}
+
+impl Default for SizednessResult {
+ fn default() -> Self {
+ SizednessResult::ZeroSized
+ }
+}
+
+impl cmp::PartialOrd for SizednessResult {
+ fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
+ use self::SizednessResult::*;
+
+ match (*self, *rhs) {
+ (x, y) if x == y => Some(cmp::Ordering::Equal),
+ (NonZeroSized, _) => Some(cmp::Ordering::Greater),
+ (_, NonZeroSized) => Some(cmp::Ordering::Less),
+ (DependsOnTypeParam, _) => Some(cmp::Ordering::Greater),
+ (_, DependsOnTypeParam) => Some(cmp::Ordering::Less),
+ _ => unreachable!(),
+ }
+ }
+}
+
+impl SizednessResult {
+ /// Take the least upper bound of `self` and `rhs`.
+ pub fn join(self, rhs: Self) -> Self {
+ cmp::max(self, rhs)
+ }
+}
+
+impl ops::BitOr for SizednessResult {
+ type Output = Self;
+
+ fn bitor(self, rhs: SizednessResult) -> Self::Output {
+ self.join(rhs)
+ }
+}
+
+impl ops::BitOrAssign for SizednessResult {
+ fn bitor_assign(&mut self, rhs: SizednessResult) {
+ *self = self.join(rhs)
+ }
+}
+
+/// An analysis that computes the sizedness of all types.
+///
+/// * For types with known sizes -- for example pointers, scalars, etc... --
+/// they are assigned `NonZeroSized`.
+///
+/// * For compound structure types with one or more fields, they are assigned
+/// `NonZeroSized`.
+///
+/// * For compound structure types without any fields, the results of the bases
+/// are `join`ed.
+///
+/// * For type parameters, `DependsOnTypeParam` is assigned.
+#[derive(Debug)]
+pub struct SizednessAnalysis<'ctx> {
+ ctx: &'ctx BindgenContext,
+ dependencies: HashMap<TypeId, Vec<TypeId>>,
+ // Incremental results of the analysis. Missing entries are implicitly
+ // considered `ZeroSized`.
+ sized: HashMap<TypeId, SizednessResult>,
+}
+
+impl<'ctx> SizednessAnalysis<'ctx> {
+ fn consider_edge(kind: EdgeKind) -> bool {
+ match kind {
+ // These are the only edges that can affect whether a type is
+ // zero-sized or not.
+ EdgeKind::TemplateArgument |
+ EdgeKind::TemplateParameterDefinition |
+ EdgeKind::TemplateDeclaration |
+ EdgeKind::TypeReference |
+ EdgeKind::BaseMember |
+ EdgeKind::Field => true,
+ _ => false,
+ }
+ }
+
+ /// Insert an incremental result, and return whether this updated our
+ /// knowledge of types and we should continue the analysis.
+ fn insert(&mut self, id: TypeId, result: SizednessResult) -> ConstrainResult {
+ trace!("inserting {:?} for {:?}", result, id);
+
+ if let SizednessResult::ZeroSized = result {
+ return ConstrainResult::Same;
+ }
+
+ match self.sized.entry(id) {
+ Entry::Occupied(mut entry) => {
+ if *entry.get() < result {
+ entry.insert(result);
+ ConstrainResult::Changed
+ } else {
+ ConstrainResult::Same
+ }
+ }
+ Entry::Vacant(entry) => {
+ entry.insert(result);
+ ConstrainResult::Changed
+ }
+ }
+ }
+
+ fn forward(&mut self, from: TypeId, to: TypeId) -> ConstrainResult {
+ match self.sized.get(&from).cloned() {
+ None => ConstrainResult::Same,
+ Some(r) => self.insert(to, r),
+ }
+ }
+}
+
+impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> {
+ type Node = TypeId;
+ type Extra = &'ctx BindgenContext;
+ type Output = HashMap<TypeId, SizednessResult>;
+
+ fn new(ctx: &'ctx BindgenContext) -> SizednessAnalysis<'ctx> {
+ let dependencies = generate_dependencies(ctx, Self::consider_edge)
+ .into_iter()
+ .filter_map(|(id, sub_ids)| {
+ id.as_type_id(ctx)
+ .map(|id| {
+ (
+ id,
+ sub_ids.into_iter()
+ .filter_map(|s| s.as_type_id(ctx))
+ .collect::<Vec<_>>()
+ )
+ })
+ })
+ .collect();
+
+ let sized = HashMap::new();
+
+ SizednessAnalysis {
+ ctx,
+ dependencies,
+ sized,
+ }
+ }
+
+ fn initial_worklist(&self) -> Vec<TypeId> {
+ self.ctx
+ .whitelisted_items()
+ .iter()
+ .cloned()
+ .filter_map(|id| id.as_type_id(self.ctx))
+ .collect()
+ }
+
+ fn constrain(&mut self, id: TypeId) -> ConstrainResult {
+ trace!("constrain {:?}", id);
+
+ if let Some(SizednessResult::NonZeroSized) = self.sized.get(&id).cloned() {
+ trace!(" already know it is not zero-sized");
+ return ConstrainResult::Same;
+ }
+
+ if id.has_vtable_ptr(self.ctx) {
+ trace!(" has an explicit vtable pointer, therefore is not zero-sized");
+ return self.insert(id, SizednessResult::NonZeroSized);
+ }
+
+ let ty = self.ctx.resolve_type(id);
+
+ if id.is_opaque(self.ctx, &()) {
+ trace!(" type is opaque; checking layout...");
+ let result = ty.layout(self.ctx)
+ .map_or(SizednessResult::ZeroSized, |l| {
+ if l.size == 0 {
+ trace!(" ...layout has size == 0");
+ SizednessResult::ZeroSized
+ } else {
+ trace!(" ...layout has size > 0");
+ SizednessResult::NonZeroSized
+ }
+ });
+ return self.insert(id, result);
+ }
+
+ match *ty.kind() {
+ TypeKind::Void => {
+ trace!(" void is zero-sized");
+ self.insert(id, SizednessResult::ZeroSized)
+ }
+
+ TypeKind::TypeParam => {
+ trace!(" type params sizedness depends on what they're \
+ instantiated as");
+ self.insert(id, SizednessResult::DependsOnTypeParam)
+ }
+
+ TypeKind::Int(..) |
+ TypeKind::Float(..) |
+ TypeKind::Complex(..) |
+ TypeKind::Function(..) |
+ TypeKind::Enum(..) |
+ TypeKind::Reference(..) |
+ TypeKind::NullPtr |
+ TypeKind::BlockPointer |
+ TypeKind::ObjCId |
+ TypeKind::ObjCSel |
+ TypeKind::Pointer(..) => {
+ trace!(" {:?} is known not to be zero-sized", ty.kind());
+ self.insert(id, SizednessResult::NonZeroSized)
+ }
+
+ TypeKind::ObjCInterface(..) => {
+ trace!(" obj-c interfaces always have at least the `isa` pointer");
+ self.insert(id, SizednessResult::NonZeroSized)
+ }
+
+ TypeKind::TemplateAlias(t, _) |
+ TypeKind::Alias(t) |
+ TypeKind::ResolvedTypeRef(t) => {
+ trace!(" aliases and type refs forward to their inner type");
+ self.forward(t, id)
+ }
+
+ TypeKind::TemplateInstantiation(ref inst) => {
+ trace!(" template instantiations are zero-sized if their \
+ definition is zero-sized");
+ self.forward(inst.template_definition(), id)
+ }
+
+ TypeKind::Array(_, 0) => {
+ trace!(" arrays of zero elements are zero-sized");
+ self.insert(id, SizednessResult::ZeroSized)
+ }
+ TypeKind::Array(..) => {
+ trace!(" arrays of > 0 elements are not zero-sized");
+ self.insert(id, SizednessResult::NonZeroSized)
+ }
+
+ TypeKind::Comp(ref info) => {
+ trace!(" comp considers its own fields and bases");
+
+ if !info.fields().is_empty() {
+ return self.insert(id, SizednessResult::NonZeroSized);
+ }
+
+ let result = info.base_members()
+ .iter()
+ .filter_map(|base| self.sized.get(&base.ty))
+ .fold(SizednessResult::ZeroSized, |a, b| a.join(*b));
+
+ self.insert(id, result)
+ }
+
+ TypeKind::Opaque => {
+ unreachable!("covered by the .is_opaque() check above")
+ }
+
+ TypeKind::UnresolvedTypeRef(..) => {
+ unreachable!("Should have been resolved after parsing!");
+ }
+ }
+ }
+
+ fn each_depending_on<F>(&self, id: TypeId, mut f: F)
+ where
+ F: FnMut(TypeId),
+ {
+ if let Some(edges) = self.dependencies.get(&id) {
+ for ty in edges {
+ trace!("enqueue {:?} into worklist", ty);
+ f(*ty);
+ }
+ }
+ }
+}
+
+impl<'ctx> From<SizednessAnalysis<'ctx>> for HashMap<TypeId, SizednessResult> {
+ fn from(analysis: SizednessAnalysis<'ctx>) -> Self {
+ // We let the lack of an entry mean "ZeroSized" to save space.
+ extra_assert!(analysis.sized.values().all(|v| {
+ *v != SizednessResult::ZeroSized
+ }));
+
+ analysis.sized
+ }
+}
+
+/// A convenience trait for querying whether some type or id is sized.
+///
+/// This is not for _computing_ whether the thing is sized, it is for looking up
+/// the results of the `Sizedness` analysis's computations for a specific thing.
+pub trait Sizedness {
+ /// Get the sizedness of this type.
+ fn sizedness(&self, ctx: &BindgenContext) -> SizednessResult;
+
+ /// Is the sizedness for this type `SizednessResult::ZeroSized`?
+ fn is_zero_sized(&self, ctx: &BindgenContext) -> bool {
+ self.sizedness(ctx) == SizednessResult::ZeroSized
+ }
+}
diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs
index 7699a0c2..00504aa4 100644
--- a/src/ir/analysis/template_params.rs
+++ b/src/ir/analysis/template_params.rs
@@ -203,7 +203,8 @@ impl<'ctx> UsedTemplateParameters<'ctx> {
}
}
- fn take_this_id_usage_set(&mut self, this_id: ItemId) -> ItemSet {
+ fn take_this_id_usage_set<Id: Into<ItemId>>(&mut self, this_id: Id) -> ItemSet {
+ let this_id = this_id.into();
self.used
.get_mut(&this_id)
.expect(
@@ -278,7 +279,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> {
debug_assert!(this_id != instantiation.template_definition());
let used_by_def = self.used
- .get(&instantiation.template_definition())
+ .get(&instantiation.template_definition().into())
.expect("Should have a used entry for instantiation's template definition")
.as_ref()
.expect("And it should be Some because only this_id's set is None, and an \
@@ -293,7 +294,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> {
param
);
- if used_by_def.contains(param) {
+ if used_by_def.contains(&param.into()) {
trace!(" param is used by template definition");
let arg = arg.into_resolver()
@@ -520,7 +521,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
// template definition uses the corresponding template parameter.
Some(&TypeKind::TemplateInstantiation(ref inst)) => {
if self.whitelisted_items.contains(
- &inst.template_definition(),
+ &inst.template_definition().into(),
)
{
self.constrain_instantiation(
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index bbccd06a..56e41d52 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -1,7 +1,8 @@
//! Compound types (unions and structs) in our intermediate representation.
+use super::analysis::Sizedness;
use super::annotations::Annotations;
-use super::context::{BindgenContext, ItemId};
+use super::context::{BindgenContext, FunctionId, ItemId, TypeId, VarId};
use super::dot::DotAttributes;
use super::item::{IsOpaque, Item};
use super::layout::Layout;
@@ -16,6 +17,7 @@ use peeking_take_while::PeekableExt;
use std::cmp;
use std::io;
use std::mem;
+use std::collections::HashMap;
/// The kind of compound type.
#[derive(Debug, Copy, Clone, PartialEq)]
@@ -52,17 +54,17 @@ pub struct Method {
/// item, but a `Function` one.
///
/// This is tricky and probably this field should be renamed.
- signature: ItemId,
+ signature: FunctionId,
is_const: bool,
}
impl Method {
/// Construct a new `Method`.
- pub fn new(kind: MethodKind, signature: ItemId, is_const: bool) -> Self {
+ pub fn new(kind: MethodKind, signature: FunctionId, is_const: bool) -> Self {
Method {
- kind: kind,
- signature: signature,
- is_const: is_const,
+ kind,
+ signature,
+ is_const,
}
}
@@ -93,8 +95,8 @@ impl Method {
self.kind == MethodKind::Static
}
- /// Get the `ItemId` for the `Function` signature for this method.
- pub fn signature(&self) -> ItemId {
+ /// Get the id for the `Function` signature for this method.
+ pub fn signature(&self) -> FunctionId {
self.signature
}
@@ -110,13 +112,13 @@ pub trait FieldMethods {
fn name(&self) -> Option<&str>;
/// Get the type of this field.
- fn ty(&self) -> ItemId;
+ fn ty(&self) -> TypeId;
/// Get the comment for this field.
fn comment(&self) -> Option<&str>;
/// If this is a bitfield, how many bits does it need?
- fn bitfield(&self) -> Option<u32>;
+ fn bitfield_width(&self) -> Option<u32>;
/// Is this field marked as `mutable`?
fn is_mutable(&self) -> bool;
@@ -191,13 +193,13 @@ impl Trace for Field {
{
match *self {
Field::DataMember(ref data) => {
- tracer.visit_kind(data.ty, EdgeKind::Field);
+ tracer.visit_kind(data.ty.into(), EdgeKind::Field);
}
Field::Bitfields(BitfieldUnit {
ref bitfields, ..
}) => {
for bf in bitfields {
- tracer.visit_kind(bf.ty(), EdgeKind::Field);
+ tracer.visit_kind(bf.ty().into(), EdgeKind::Field);
}
}
}
@@ -275,7 +277,7 @@ impl DotAttributes for Bitfield {
writeln!(
out,
"<tr><td>{} : {}</td><td>{:?}</td></tr>",
- self.name(),
+ self.name().unwrap_or("(anonymous)"),
self.width(),
self.ty()
)
@@ -291,17 +293,28 @@ pub struct Bitfield {
/// The field data for this bitfield.
data: FieldData,
+
+ /// Name of the generated Rust getter for this bitfield.
+ ///
+ /// Should be assigned before codegen.
+ getter_name: Option<String>,
+
+ /// Name of the generated Rust setter for this bitfield.
+ ///
+ /// Should be assigned before codegen.
+ setter_name: Option<String>,
}
impl Bitfield {
/// Construct a new bitfield.
fn new(offset_into_unit: usize, raw: RawField) -> Bitfield {
- assert!(raw.bitfield().is_some());
- assert!(raw.name().is_some());
+ assert!(raw.bitfield_width().is_some());
Bitfield {
- offset_into_unit: offset_into_unit,
+ offset_into_unit,
data: raw.0,
+ getter_name: None,
+ setter_name: None,
}
}
@@ -329,12 +342,31 @@ impl Bitfield {
/// Get the bit width of this bitfield.
pub fn width(&self) -> u32 {
- self.data.bitfield().unwrap()
+ self.data.bitfield_width().unwrap()
+ }
+
+ /// Name of the generated Rust getter for this bitfield.
+ ///
+ /// Panics if called before assigning bitfield accessor names or if
+ /// this bitfield have no name.
+ pub fn getter_name(&self) -> &str {
+ assert!(self.name().is_some(), "`Bitfield::getter_name` called on anonymous field");
+ self.getter_name.as_ref().expect(
+ "`Bitfield::getter_name` should only be called after\
+ assigning bitfield accessor names",
+ )
}
- /// Get the name of this bitfield.
- pub fn name(&self) -> &str {
- self.data.name().unwrap()
+ /// Name of the generated Rust setter for this bitfield.
+ ///
+ /// Panics if called before assigning bitfield accessor names or if
+ /// this bitfield have no name.
+ pub fn setter_name(&self) -> &str {
+ assert!(self.name().is_some(), "`Bitfield::setter_name` called on anonymous field");
+ self.setter_name.as_ref().expect(
+ "`Bitfield::setter_name` should only be called\
+ after assigning bitfield accessor names",
+ )
}
}
@@ -343,7 +375,7 @@ impl FieldMethods for Bitfield {
self.data.name()
}
- fn ty(&self) -> ItemId {
+ fn ty(&self) -> TypeId {
self.data.ty()
}
@@ -351,8 +383,8 @@ impl FieldMethods for Bitfield {
self.data.comment()
}
- fn bitfield(&self) -> Option<u32> {
- self.data.bitfield()
+ fn bitfield_width(&self) -> Option<u32> {
+ self.data.bitfield_width()
}
fn is_mutable(&self) -> bool {
@@ -380,21 +412,21 @@ impl RawField {
/// Construct a new `RawField`.
fn new(
name: Option<String>,
- ty: ItemId,
+ ty: TypeId,
comment: Option<String>,
annotations: Option<Annotations>,
- bitfield: Option<u32>,
+ bitfield_width: Option<u32>,
mutable: bool,
offset: Option<usize>,
) -> RawField {
RawField(FieldData {
- name: name,
- ty: ty,
- comment: comment,
+ name,
+ ty,
+ comment,
annotations: annotations.unwrap_or_default(),
- bitfield: bitfield,
- mutable: mutable,
- offset: offset,
+ bitfield_width,
+ mutable,
+ offset,
})
}
}
@@ -404,7 +436,7 @@ impl FieldMethods for RawField {
self.0.name()
}
- fn ty(&self) -> ItemId {
+ fn ty(&self) -> TypeId {
self.0.ty()
}
@@ -412,8 +444,8 @@ impl FieldMethods for RawField {
self.0.comment()
}
- fn bitfield(&self) -> Option<u32> {
- self.0.bitfield()
+ fn bitfield_width(&self) -> Option<u32> {
+ self.0.bitfield_width()
}
fn is_mutable(&self) -> bool {
@@ -449,7 +481,7 @@ where
{
let non_bitfields = raw_fields
.by_ref()
- .peeking_take_while(|f| f.bitfield().is_none())
+ .peeking_take_while(|f| f.bitfield_width().is_none())
.map(|f| Field::DataMember(f.0));
fields.extend(non_bitfields);
}
@@ -459,7 +491,7 @@ where
// the Itanium C++ ABI.
let mut bitfields = raw_fields
.by_ref()
- .peeking_take_while(|f| f.bitfield().is_some())
+ .peeking_take_while(|f| f.bitfield_width().is_some())
.peekable();
if bitfields.peek().is_none() {
@@ -537,7 +569,7 @@ fn bitfields_to_allocation_units<E, I>(
const is_ms_struct: bool = false;
for bitfield in raw_bitfields {
- let bitfield_width = bitfield.bitfield().unwrap() as usize;
+ let bitfield_width = bitfield.bitfield_width().unwrap() as usize;
let bitfield_layout = ctx.resolve_type(bitfield.ty())
.layout(ctx)
.expect("Bitfield without layout? Gah!");
@@ -580,13 +612,12 @@ fn bitfields_to_allocation_units<E, I>(
}
}
- // Only keep named bitfields around. Unnamed bitfields (with > 0
- // bitsize) are used for padding. Because the `Bitfield` struct stores
- // the bit-offset into its allocation unit where its bits begin, we
- // don't need any padding bits hereafter.
- if bitfield.name().is_some() {
- bitfields_in_unit.push(Bitfield::new(offset, bitfield));
- }
+ // Always keep all bitfields around. While unnamed bitifields are used
+ // for padding (and usually not needed hereafter), large unnamed
+ // bitfields over their types size cause weird allocation size behavior from clang.
+ // Therefore, all bitfields needed to be kept around in order to check for this
+ // and make the struct opaque in this case
+ bitfields_in_unit.push(Bitfield::new(offset, bitfield));
max_align = cmp::max(max_align, bitfield_align);
@@ -666,6 +697,82 @@ impl CompFields {
CompFields::AfterComputingBitfieldUnits(fields_and_units),
);
}
+
+ fn deanonymize_fields(&mut self, ctx: &BindgenContext, methods: &[Method]) {
+ let fields = match *self {
+ CompFields::AfterComputingBitfieldUnits(ref mut fields) => fields,
+ CompFields::BeforeComputingBitfieldUnits(_) => {
+ panic!("Not yet computed bitfield units.");
+ }
+ };
+
+ fn has_method(methods: &[Method], ctx: &BindgenContext, name: &str) -> bool {
+ methods.iter().any(|method| {
+ let method_name = ctx.resolve_func(method.signature()).name();
+ method_name == name || ctx.rust_mangle(&method_name) == name
+ })
+ }
+
+ struct AccessorNamesPair {
+ getter: String,
+ setter: String,
+ }
+
+ let mut accessor_names: HashMap<String, AccessorNamesPair> = fields
+ .iter()
+ .flat_map(|field| match *field {
+ Field::Bitfields(ref bu) => &*bu.bitfields,
+ Field::DataMember(_) => &[],
+ })
+ .filter_map(|bitfield| bitfield.name())
+ .map(|bitfield_name| {
+ let bitfield_name = bitfield_name.to_string();
+ let getter = {
+ let mut getter = ctx.rust_mangle(&bitfield_name).to_string();
+ if has_method(methods, ctx, &getter) {
+ getter.push_str("_bindgen_bitfield");
+ }
+ getter
+ };
+ let setter = {
+ 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");
+ }
+ setter
+ };
+ (bitfield_name, AccessorNamesPair { getter, setter })
+ })
+ .collect();
+
+ let mut anon_field_counter = 0;
+ for field in fields.iter_mut() {
+ match *field {
+ Field::DataMember(FieldData { ref mut name, .. }) => {
+ if let Some(_) = *name {
+ continue;
+ }
+
+ anon_field_counter += 1;
+ let generated_name = format!("__bindgen_anon_{}", anon_field_counter);
+ *name = Some(generated_name);
+ }
+ Field::Bitfields(ref mut bu) => for bitfield in &mut bu.bitfields {
+ if bitfield.name().is_none() {
+ continue;
+ }
+
+ if let Some(AccessorNamesPair { getter, setter }) =
+ accessor_names.remove(bitfield.name().unwrap())
+ {
+ bitfield.getter_name = Some(getter);
+ bitfield.setter_name = Some(setter);
+ }
+ },
+ }
+ }
+ }
}
impl Trace for CompFields {
@@ -678,7 +785,7 @@ impl Trace for CompFields {
match *self {
CompFields::BeforeComputingBitfieldUnits(ref fields) => {
for f in fields {
- tracer.visit_kind(f.ty(), EdgeKind::Field);
+ tracer.visit_kind(f.ty().into(), EdgeKind::Field);
}
}
CompFields::AfterComputingBitfieldUnits(ref fields) => {
@@ -697,7 +804,7 @@ pub struct FieldData {
name: Option<String>,
/// The inner type.
- ty: ItemId,
+ ty: TypeId,
/// The doc comment on the field if any.
comment: Option<String>,
@@ -706,7 +813,7 @@ pub struct FieldData {
annotations: Annotations,
/// If this field is a bitfield, and how many bits does it contain if it is.
- bitfield: Option<u32>,
+ bitfield_width: Option<u32>,
/// If the C++ field is marked as `mutable`
mutable: bool,
@@ -720,7 +827,7 @@ impl FieldMethods for FieldData {
self.name.as_ref().map(|n| &**n)
}
- fn ty(&self) -> ItemId {
+ fn ty(&self) -> TypeId {
self.ty
}
@@ -728,8 +835,8 @@ impl FieldMethods for FieldData {
self.comment.as_ref().map(|c| &**c)
}
- fn bitfield(&self) -> Option<u32> {
- self.bitfield
+ fn bitfield_width(&self) -> Option<u32> {
+ self.bitfield_width
}
fn is_mutable(&self) -> bool {
@@ -766,9 +873,11 @@ pub enum BaseKind {
#[derive(Clone, Debug)]
pub struct Base {
/// The type of this base class.
- pub ty: ItemId,
+ pub ty: TypeId,
/// The kind of inheritance we're doing.
pub kind: BaseKind,
+ /// Name of the field in which this base should be stored.
+ pub field_name: String,
}
impl Base {
@@ -776,6 +885,26 @@ impl Base {
pub fn is_virtual(&self) -> bool {
self.kind == BaseKind::Virtual
}
+
+ /// Whether this base class should have it's own field for storage.
+ pub fn requires_storage(&self, ctx: &BindgenContext) -> bool {
+ // Virtual bases are already taken into account by the vtable
+ // pointer.
+ //
+ // FIXME(emilio): Is this always right?
+ if self.is_virtual() {
+ return false;
+ }
+
+ // NB: We won't include zero-sized types in our base chain because they
+ // would contribute to our size given the dummy field we insert for
+ // zero-sized types.
+ if self.ty.is_zero_sized(ctx) {
+ return false;
+ }
+
+ true
+ }
}
/// A compound type.
@@ -795,17 +924,17 @@ pub struct CompInfo {
/// concrete template arguments, and should always be a
/// `Type(TypeKind::TypeParam(name))`. For concrete template arguments, see
/// `TypeKind::TemplateInstantiation`.
- template_params: Vec<ItemId>,
+ template_params: Vec<TypeId>,
/// The method declarations inside this class, if in C++ mode.
methods: Vec<Method>,
/// The different constructors this struct or class contains.
- constructors: Vec<ItemId>,
+ constructors: Vec<FunctionId>,
/// The destructor of this type. The bool represents whether this destructor
/// is virtual.
- destructor: Option<(bool, ItemId)>,
+ destructor: Option<(bool, FunctionId)>,
/// Vector of classes this one inherits from.
base_members: Vec<Base>,
@@ -820,10 +949,10 @@ pub struct CompInfo {
/// }
///
/// static Foo::Bar const = {3};
- inner_types: Vec<ItemId>,
+ inner_types: Vec<TypeId>,
/// Set of static constants declared inside this class.
- inner_vars: Vec<ItemId>,
+ inner_vars: Vec<VarId>,
/// Whether this type should generate an vtable (TODO: Should be able to
/// look at the virtual methods and ditch this field).
@@ -880,17 +1009,6 @@ impl CompInfo {
}
}
- /// Is this compound type unsized?
- pub fn is_unsized(&self, ctx: &BindgenContext, itemid: &ItemId) -> bool {
- !ctx.lookup_item_id_has_vtable(itemid) && self.fields().is_empty() &&
- self.base_members.iter().all(|base| {
- ctx.resolve_type(base.ty).canonical_type(ctx).is_unsized(
- ctx,
- &base.ty,
- )
- })
- }
-
/// Compute the layout of this type.
///
/// This is called as a fallback under some circumstances where LLVM doesn't
@@ -954,12 +1072,12 @@ impl CompInfo {
}
/// Get this type's set of constructors.
- pub fn constructors(&self) -> &[ItemId] {
+ pub fn constructors(&self) -> &[FunctionId] {
&self.constructors
}
/// Get this type's destructor.
- pub fn destructor(&self) -> Option<(bool, ItemId)> {
+ pub fn destructor(&self) -> Option<(bool, FunctionId)> {
self.destructor
}
@@ -1075,12 +1193,12 @@ impl CompInfo {
let name = if name.is_empty() { None } else { Some(name) };
let field = RawField::new(name,
- field_type,
- comment,
- annotations,
- bit_width,
- is_mutable,
- offset);
+ field_type,
+ comment,
+ annotations,
+ bit_width,
+ is_mutable,
+ offset);
ci.fields.append_raw_field(field);
// No we look for things like attributes and stuff.
@@ -1123,6 +1241,9 @@ impl CompInfo {
let inner = Item::parse(cur, Some(potential_id), ctx)
.expect("Inner ClassDecl");
+ assert_eq!(ctx.resolve_item(inner).parent_id(), potential_id);
+
+ let inner = inner.expect_type_id(ctx);
ci.inner_types.push(inner);
@@ -1132,8 +1253,7 @@ impl CompInfo {
cur.kind() != CXCursor_EnumDecl {
let ty = cur.cur_type();
let offset = cur.offset_of_field().ok();
- maybe_anonymous_struct_field =
- Some((inner, ty, offset));
+ maybe_anonymous_struct_field = Some((inner, ty, offset));
}
}
CXCursor_PackedAttr => {
@@ -1155,11 +1275,16 @@ impl CompInfo {
BaseKind::Normal
};
+ let field_name = match ci.base_members.len() {
+ 0 => "_base".into(),
+ n => format!("_base_{}", n),
+ };
let type_id =
Item::from_ty_or_ref(cur.cur_type(), cur, None, ctx);
ci.base_members.push(Base {
ty: type_id,
kind: kind,
+ field_name: field_name,
});
}
CXCursor_Constructor |
@@ -1196,6 +1321,8 @@ impl CompInfo {
_ => return CXChildVisit_Continue,
};
+ let signature = signature.expect_function_id(ctx);
+
match cur.kind() {
CXCursor_Constructor => {
ci.constructors.push(signature);
@@ -1239,7 +1366,7 @@ impl CompInfo {
if let Ok(item) = Item::parse(cur,
Some(potential_id),
ctx) {
- ci.inner_vars.push(item);
+ ci.inner_vars.push(item.as_var_id_unchecked());
}
}
// Intentionally not handled
@@ -1292,12 +1419,12 @@ impl CompInfo {
/// Get the set of types that were declared within this compound type
/// (e.g. nested class definitions).
- pub fn inner_types(&self) -> &[ItemId] {
+ pub fn inner_types(&self) -> &[TypeId] {
&self.inner_types
}
/// Get the set of static variables declared within this compound type.
- pub fn inner_vars(&self) -> &[ItemId] {
+ pub fn inner_vars(&self) -> &[VarId] {
&self.inner_vars
}
@@ -1312,28 +1439,6 @@ impl CompInfo {
self.packed
}
- /// Returns whether this type needs an explicit vtable because it has
- /// virtual methods and none of its base classes has already a vtable.
- pub fn needs_explicit_vtable(
- &self,
- ctx: &BindgenContext,
- item: &Item,
- ) -> bool {
- ctx.lookup_item_id_has_vtable(&item.id()) &&
- !self.base_members.iter().any(|base| {
- // NB: Ideally, we could rely in all these types being `comp`, and
- // life would be beautiful.
- //
- // Unfortunately, given the way we implement --match-pat, and also
- // that you can inherit from templated types, we need to handle
- // other cases here too.
- ctx.resolve_type(base.ty)
- .canonical_type(ctx)
- .as_comp()
- .map_or(false, |_| ctx.lookup_item_id_has_vtable(&base.ty))
- })
- }
-
/// Returns true if compound type has been forward declared
pub fn is_forward_declaration(&self) -> bool {
self.is_forward_declaration
@@ -1344,6 +1449,11 @@ impl CompInfo {
self.fields.compute_bitfield_units(ctx);
}
+ /// Assign for each anonymous field a generated name.
+ pub fn deanonymize_fields(&mut self, ctx: &BindgenContext) {
+ self.fields.deanonymize_fields(ctx, &self.methods);
+ }
+
/// Returns whether the current union can be represented as a Rust `union`
///
/// Requirements:
@@ -1355,7 +1465,7 @@ impl CompInfo {
Field::DataMember(ref field_data) => {
field_data.ty().can_derive_copy(ctx)
}
- Field::Bitfields(_) => false,
+ Field::Bitfields(_) => true,
})
}
}
@@ -1416,8 +1526,25 @@ impl DotAttributes for CompInfo {
impl IsOpaque for CompInfo {
type Extra = ();
- fn is_opaque(&self, _: &BindgenContext, _: &()) -> bool {
- self.has_non_type_template_params
+ fn is_opaque(&self, ctx: &BindgenContext, _: &()) -> bool {
+ // Early return to avoid extra computation
+ if self.has_non_type_template_params {
+ return true
+ }
+
+ self.fields().iter().any(|f| match *f {
+ Field::DataMember(_) => {
+ false
+ },
+ Field::Bitfields(ref unit) => {
+ unit.bitfields().iter().any(|bf| {
+ let bitfield_layout = ctx.resolve_type(bf.ty())
+ .layout(ctx)
+ .expect("Bitfield without layout? Gah!");
+ bf.width() / 8 > bitfield_layout.size as u32
+ })
+ }
+ })
}
}
@@ -1425,7 +1552,7 @@ impl TemplateParameters for CompInfo {
fn self_template_params(
&self,
_ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
if self.template_params.is_empty() {
None
} else {
@@ -1443,27 +1570,27 @@ impl Trace for CompInfo {
{
let params = item.all_template_params(context).unwrap_or(vec![]);
for p in params {
- tracer.visit_kind(p, EdgeKind::TemplateParameterDefinition);
+ tracer.visit_kind(p.into(), EdgeKind::TemplateParameterDefinition);
}
- for &ty in self.inner_types() {
- tracer.visit_kind(ty, EdgeKind::InnerType);
+ for ty in self.inner_types() {
+ tracer.visit_kind(ty.into(), EdgeKind::InnerType);
}
for &var in self.inner_vars() {
- tracer.visit_kind(var, EdgeKind::InnerVar);
+ tracer.visit_kind(var.into(), EdgeKind::InnerVar);
}
for method in self.methods() {
if method.is_destructor() {
- tracer.visit_kind(method.signature, EdgeKind::Destructor);
+ tracer.visit_kind(method.signature.into(), EdgeKind::Destructor);
} else {
- tracer.visit_kind(method.signature, EdgeKind::Method);
+ tracer.visit_kind(method.signature.into(), EdgeKind::Method);
}
}
- for &ctor in self.constructors() {
- tracer.visit_kind(ctor, EdgeKind::Constructor);
+ for ctor in self.constructors() {
+ tracer.visit_kind(ctor.into(), EdgeKind::Constructor);
}
// Base members and fields are not generated for opaque types (but all
@@ -1473,7 +1600,7 @@ impl Trace for CompInfo {
}
for base in self.base_members() {
- tracer.visit_kind(base.ty, EdgeKind::BaseMember);
+ tracer.visit_kind(base.ty.into(), EdgeKind::BaseMember);
}
self.fields.trace(context, tracer, &());
diff --git a/src/ir/context.rs b/src/ir/context.rs
index bb0dc6cf..138a69b9 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -1,20 +1,22 @@
//! Common context that is passed around during parsing and codegen.
-use super::analysis::{CannotDeriveCopy, CannotDeriveDebug,
- CannotDeriveDefault, CannotDeriveHash,
- CannotDerivePartialEq, HasTypeParameterInArray,
- HasVtableAnalysis, HasDestructorAnalysis, UsedTemplateParameters,
- HasFloat, analyze};
+use super::analysis::{CannotDeriveCopy, CannotDeriveDebug, CannotDeriveDefault,
+ CannotDeriveHash, CannotDerivePartialEqOrPartialOrd,
+ HasTypeParameterInArray, HasVtableAnalysis,
+ HasVtableResult, HasDestructorAnalysis,
+ UsedTemplateParameters, HasFloat, SizednessAnalysis,
+ SizednessResult, analyze};
use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault,
- CanDeriveHash, CanDerivePartialEq, CanDeriveEq};
+ CanDeriveHash, CanDerivePartialOrd, CanDeriveOrd,
+ CanDerivePartialEq, CanDeriveEq, CannotDeriveReason};
use super::int::IntKind;
-use super::item::{HasTypeParamInArray, IsOpaque, Item, ItemAncestors,
- ItemCanonicalPath, ItemSet};
+use super::item::{IsOpaque, Item, ItemAncestors, ItemCanonicalPath, ItemSet};
use super::item_kind::ItemKind;
use super::module::{Module, ModuleKind};
use super::template::{TemplateInstantiation, TemplateParameters};
use super::traversal::{self, Edge, ItemTraversal};
use super::ty::{FloatKind, Type, TypeKind};
+use super::function::Function;
use super::super::time::Timer;
use BindgenOptions;
use callbacks::ParseCallbacks;
@@ -30,56 +32,258 @@ use std::collections::btree_map::{self, BTreeMap};
use std::iter::IntoIterator;
use std::mem;
-/// A single identifier for an item.
-///
-/// TODO: Build stronger abstractions on top of this, like TypeId(ItemId)?
-#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+/// An identifier for some kind of IR item.
+#[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)]
pub struct ItemId(usize);
+macro_rules! item_id_newtype {
+ (
+ $( #[$attr:meta] )*
+ pub struct $name:ident(ItemId)
+ where
+ $( #[$checked_attr:meta] )*
+ checked = $checked:ident with $check_method:ident,
+ $( #[$expected_attr:meta] )*
+ expected = $expected:ident,
+ $( #[$unchecked_attr:meta] )*
+ unchecked = $unchecked:ident;
+ ) => {
+ $( #[$attr] )*
+ #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)]
+ pub struct $name(ItemId);
+
+ impl $name {
+ /// Create an `ItemResolver` from this id.
+ pub fn into_resolver(self) -> ItemResolver {
+ let id: ItemId = self.into();
+ id.into()
+ }
+ }
+
+ impl<T> ::std::cmp::PartialEq<T> for $name
+ where
+ T: Copy + Into<ItemId>
+ {
+ fn eq(&self, rhs: &T) -> bool {
+ let rhs: ItemId = (*rhs).into();
+ self.0 == rhs
+ }
+ }
+
+ impl From<$name> for ItemId {
+ fn from(id: $name) -> ItemId {
+ id.0
+ }
+ }
+
+ impl<'a> From<&'a $name> for ItemId {
+ fn from(id: &'a $name) -> ItemId {
+ id.0
+ }
+ }
+
+ impl ItemId {
+ $( #[$checked_attr] )*
+ pub fn $checked(&self, ctx: &BindgenContext) -> Option<$name> {
+ if ctx.resolve_item(*self).kind().$check_method() {
+ Some($name(*self))
+ } else {
+ None
+ }
+ }
+
+ $( #[$expected_attr] )*
+ pub fn $expected(&self, ctx: &BindgenContext) -> $name {
+ self.$checked(ctx)
+ .expect(concat!(
+ stringify!($expected),
+ " called with ItemId that points to the wrong ItemKind"
+ ))
+ }
+
+ $( #[$unchecked_attr] )*
+ pub fn $unchecked(&self) -> $name {
+ $name(*self)
+ }
+ }
+ }
+}
+
+item_id_newtype! {
+ /// An identifier for an `Item` whose `ItemKind` is known to be
+ /// `ItemKind::Type`.
+ pub struct TypeId(ItemId)
+ where
+ /// Convert this `ItemId` into a `TypeId` if its associated item is a type,
+ /// otherwise return `None`.
+ checked = as_type_id with is_type,
+
+ /// Convert this `ItemId` into a `TypeId`.
+ ///
+ /// If this `ItemId` does not point to a type, then panic.
+ expected = expect_type_id,
+
+ /// Convert this `ItemId` into a `TypeId` without actually checking whether
+ /// this id actually points to a `Type`.
+ unchecked = as_type_id_unchecked;
+}
+
+item_id_newtype! {
+ /// An identifier for an `Item` whose `ItemKind` is known to be
+ /// `ItemKind::Module`.
+ pub struct ModuleId(ItemId)
+ where
+ /// Convert this `ItemId` into a `ModuleId` if its associated item is a
+ /// module, otherwise return `None`.
+ checked = as_module_id with is_module,
+
+ /// Convert this `ItemId` into a `ModuleId`.
+ ///
+ /// If this `ItemId` does not point to a module, then panic.
+ expected = expect_module_id,
+
+ /// Convert this `ItemId` into a `ModuleId` without actually checking
+ /// whether this id actually points to a `Module`.
+ unchecked = as_module_id_unchecked;
+}
+
+item_id_newtype! {
+ /// An identifier for an `Item` whose `ItemKind` is known to be
+ /// `ItemKind::Var`.
+ pub struct VarId(ItemId)
+ where
+ /// Convert this `ItemId` into a `VarId` if its associated item is a var,
+ /// otherwise return `None`.
+ checked = as_var_id with is_var,
+
+ /// Convert this `ItemId` into a `VarId`.
+ ///
+ /// If this `ItemId` does not point to a var, then panic.
+ expected = expect_var_id,
+
+ /// Convert this `ItemId` into a `VarId` without actually checking whether
+ /// this id actually points to a `Var`.
+ unchecked = as_var_id_unchecked;
+}
+
+item_id_newtype! {
+ /// An identifier for an `Item` whose `ItemKind` is known to be
+ /// `ItemKind::Function`.
+ pub struct FunctionId(ItemId)
+ where
+ /// Convert this `ItemId` into a `FunctionId` if its associated item is a function,
+ /// otherwise return `None`.
+ checked = as_function_id with is_function,
+
+ /// Convert this `ItemId` into a `FunctionId`.
+ ///
+ /// If this `ItemId` does not point to a function, then panic.
+ expected = expect_function_id,
+
+ /// Convert this `ItemId` into a `FunctionId` without actually checking whether
+ /// this id actually points to a `Function`.
+ unchecked = as_function_id_unchecked;
+}
+
+impl From<ItemId> for usize {
+ fn from(id: ItemId) -> usize {
+ id.0
+ }
+}
+
impl ItemId {
/// Get a numeric representation of this id.
pub fn as_usize(&self) -> usize {
- self.0
+ (*self).into()
+ }
+}
+
+impl<T> ::std::cmp::PartialEq<T> for ItemId
+where
+ T: Copy + Into<ItemId>
+{
+ fn eq(&self, rhs: &T) -> bool {
+ let rhs: ItemId = (*rhs).into();
+ self.0 == rhs.0
}
}
-impl CanDeriveDebug for ItemId {
+impl<T> CanDeriveDebug for T
+where
+ T: Copy + Into<ItemId>
+{
fn can_derive_debug(&self, ctx: &BindgenContext) -> bool {
- ctx.options().derive_debug && ctx.lookup_item_id_can_derive_debug(*self)
+ ctx.options().derive_debug && ctx.lookup_can_derive_debug(*self)
}
}
-impl CanDeriveDefault for ItemId {
+impl<T> CanDeriveDefault for T
+where
+ T: Copy + Into<ItemId>
+{
fn can_derive_default(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_default &&
- ctx.lookup_item_id_can_derive_default(*self)
+ ctx.lookup_can_derive_default(*self)
}
}
-impl<'a> CanDeriveCopy<'a> for ItemId {
+impl<'a, T> CanDeriveCopy<'a> for T
+where
+ T: Copy + Into<ItemId>
+{
fn can_derive_copy(&self, ctx: &BindgenContext) -> bool {
- ctx.lookup_item_id_can_derive_copy(*self)
+ ctx.lookup_can_derive_copy(*self)
}
}
-impl CanDeriveHash for ItemId {
+impl<T> CanDeriveHash for T
+where
+ T: Copy + Into<ItemId>
+{
fn can_derive_hash(&self, ctx: &BindgenContext) -> bool {
- ctx.options().derive_hash && ctx.lookup_item_id_can_derive_hash(*self)
+ ctx.options().derive_hash && ctx.lookup_can_derive_hash(*self)
+ }
+}
+
+impl<T> CanDerivePartialOrd for T
+where
+ T: Copy + Into<ItemId>
+{
+ fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool {
+ ctx.options().derive_partialord &&
+ ctx.lookup_can_derive_partialeq_or_partialord(*self).is_none()
}
}
-impl CanDerivePartialEq for ItemId {
+impl<T> CanDerivePartialEq for T
+where
+ T: Copy + Into<ItemId>
+{
fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_partialeq &&
- ctx.lookup_item_id_can_derive_partialeq(*self)
+ ctx.lookup_can_derive_partialeq_or_partialord(*self).is_none()
}
}
-impl CanDeriveEq for ItemId {
+impl<T> CanDeriveEq for T
+where
+ T: Copy + Into<ItemId>
+{
fn can_derive_eq(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_eq &&
- ctx.lookup_item_id_can_derive_partialeq(*self) &&
- !ctx.lookup_item_id_has_float(&self)
+ ctx.lookup_can_derive_partialeq_or_partialord(*self).is_none() &&
+ !ctx.lookup_has_float(*self)
+ }
+}
+
+impl<T> CanDeriveOrd for T
+where
+ T: Copy + Into<ItemId>
+{
+ fn can_derive_ord(&self, ctx: &BindgenContext) -> bool {
+ ctx.options().derive_ord &&
+ ctx.lookup_can_derive_partialeq_or_partialord(*self).is_none() &&
+ !ctx.lookup_has_float(*self)
}
}
@@ -109,20 +313,20 @@ pub struct BindgenContext {
/// Clang USR to type map. This is needed to be able to associate types with
/// item ids during parsing.
- types: HashMap<TypeKey, ItemId>,
+ types: HashMap<TypeKey, TypeId>,
/// Maps from a cursor to the item id of the named template type parameter
/// for that cursor.
- type_params: HashMap<clang::Cursor, ItemId>,
+ type_params: HashMap<clang::Cursor, TypeId>,
/// A cursor to module map. Similar reason than above.
- modules: HashMap<Cursor, ItemId>,
+ modules: HashMap<Cursor, ModuleId>,
/// The root module, this is guaranteed to be an item of kind Module.
- root_module: ItemId,
+ root_module: ModuleId,
/// Current module being traversed.
- current_module: ItemId,
+ current_module: ModuleId,
/// A HashMap keyed on a type definition, and whose value is the parent id
/// of the declaration.
@@ -188,9 +392,6 @@ pub struct BindgenContext {
/// bitfield allocation units computed. Drained in `compute_bitfield_units`.
need_bitfield_allocation: Vec<ItemId>,
- /// Whether we need the mangling hack which removes the prefixing underscore.
- needs_mangling_hack: bool,
-
/// The set of (`ItemId`s of) types that can't derive debug.
///
/// This is populated when we enter codegen by `compute_cannot_derive_debug`
@@ -221,17 +422,24 @@ pub struct BindgenContext {
/// and is always `None` before that and `Some` after.
cannot_derive_hash: Option<HashSet<ItemId>>,
- /// The set of (`ItemId`s of) types that can't derive hash.
+ /// The map why specified `ItemId`s of) types that can't derive hash.
///
- /// This is populated when we enter codegen by `compute_can_derive_partialeq`
- /// and is always `None` before that and `Some` after.
- cannot_derive_partialeq: Option<HashSet<ItemId>>,
+ /// This is populated when we enter codegen by
+ /// `compute_cannot_derive_partialord_partialeq_or_eq` and is always `None`
+ /// before that and `Some` after.
+ cannot_derive_partialeq_or_partialord: Option<HashMap<ItemId, CannotDeriveReason>>,
+
+ /// The sizedness of types.
+ ///
+ /// This is populated by `compute_sizedness` and is always `None` before
+ /// that function is invoked and `Some` afterwards.
+ sizedness: Option<HashMap<TypeId, SizednessResult>>,
/// The set of (`ItemId's of`) types that has vtable.
///
/// Populated when we enter codegen by `compute_has_vtable`; always `None`
/// before that and `Some` after.
- have_vtable: Option<HashSet<ItemId>>,
+ have_vtable: Option<HashMap<ItemId, HasVtableResult>>,
/// The set of (`ItemId's of`) types that has destructor.
///
@@ -290,7 +498,7 @@ impl<'ctx> WhitelistedItemsTraversal<'ctx> {
R: IntoIterator<Item = ItemId>,
{
WhitelistedItemsTraversal {
- ctx: ctx,
+ ctx,
traversal: ItemTraversal::new(ctx, roots, predicate),
}
}
@@ -321,7 +529,7 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) {
impl BindgenContext {
/// Construct the context for the given `options`.
- pub fn new(options: BindgenOptions) -> Self {
+ pub(crate) fn new(options: BindgenOptions) -> Self {
use clang_sys;
// TODO(emilio): Use the CXTargetInfo here when available.
@@ -354,24 +562,17 @@ impl BindgenContext {
).expect("TranslationUnit::parse failed")
};
- // Mac os, iOS and Win32 need __ for mangled symbols but rust will
- // automatically prepend the extra _.
- //
- // We need to make sure that we don't include __ because rust will turn
- // into ___.
- let needs_mangling_hack = effective_target.contains("darwin") ||
- effective_target.contains("ios") ||
- effective_target == "i686-pc-win32";
-
let root_module = Self::build_root_module(ItemId(0));
+ let root_module_id = root_module.id().as_module_id_unchecked();
+
let mut me = BindgenContext {
items: Default::default(),
types: Default::default(),
type_params: Default::default(),
modules: Default::default(),
next_item_id: ItemId(1),
- root_module: root_module.id(),
- current_module: root_module.id(),
+ root_module: root_module_id,
+ current_module: root_module_id,
semantic_parents: Default::default(),
currently_parsed_types: vec![],
parsed_macros: Default::default(),
@@ -386,13 +587,13 @@ impl BindgenContext {
codegen_items: None,
used_template_parameters: None,
need_bitfield_allocation: Default::default(),
- needs_mangling_hack: needs_mangling_hack,
cannot_derive_debug: None,
cannot_derive_default: None,
cannot_derive_copy: None,
cannot_derive_copy_in_array: None,
cannot_derive_hash: None,
- cannot_derive_partialeq: None,
+ cannot_derive_partialeq_or_partialord: None,
+ sizedness: None,
have_vtable: None,
have_destructor: None,
has_type_param_in_array: None,
@@ -520,7 +721,7 @@ impl BindgenContext {
TypeKey::Declaration(declaration)
};
- let old = self.types.insert(key, id);
+ let old = self.types.insert(key, id.as_type_id_unchecked());
debug_assert_eq!(old, None);
}
}
@@ -553,7 +754,7 @@ impl BindgenContext {
);
self.items
- .get_mut(&self.current_module)
+ .get_mut(&self.current_module.into())
.expect("Should always have an item for self.current_module")
.as_module_mut()
.expect("self.current_module should always be a module")
@@ -587,7 +788,7 @@ impl BindgenContext {
"should not have already associated an item with the given id"
);
- let old_named_ty = self.type_params.insert(definition, id);
+ let old_named_ty = self.type_params.insert(definition, id.as_type_id_unchecked());
assert!(
old_named_ty.is_none(),
"should not have already associated a named type with this id"
@@ -596,7 +797,7 @@ impl BindgenContext {
/// Get the named type defined at the given cursor location, if we've
/// already added one.
- pub fn get_type_param(&self, definition: &clang::Cursor) -> Option<ItemId> {
+ pub fn get_type_param(&self, definition: &clang::Cursor) -> Option<TypeId> {
assert_eq!(
definition.kind(),
clang_sys::CXCursor_TemplateTypeParameter
@@ -664,7 +865,8 @@ impl BindgenContext {
"where" |
"while" |
"yield" |
- "bool" => true,
+ "bool" |
+ "_" => true,
_ => false,
}
{
@@ -733,28 +935,55 @@ impl BindgenContext {
let typerefs = self.collect_typerefs();
for (id, ty, loc, parent_id) in typerefs {
- let _resolved =
- {
- let resolved = Item::from_ty(&ty, loc, parent_id, self)
+ let _resolved = {
+ let resolved = Item::from_ty(&ty, loc, parent_id, self)
.unwrap_or_else(|_| {
warn!("Could not resolve type reference, falling back \
to opaque blob");
Item::new_opaque_type(self.next_item_id(), &ty, self)
});
- let item = self.items.get_mut(&id).unwrap();
- *item.kind_mut().as_type_mut().unwrap().kind_mut() =
- TypeKind::ResolvedTypeRef(resolved);
- resolved
- };
+ let item = self.items.get_mut(&id).unwrap();
+ *item.kind_mut().as_type_mut().unwrap().kind_mut() =
+ TypeKind::ResolvedTypeRef(resolved);
+ resolved
+ };
// Something in the STL is trolling me. I don't need this assertion
// right now, but worth investigating properly once this lands.
//
// debug_assert!(self.items.get(&resolved).is_some(), "How?");
+ //
+ // if let Some(parent_id) = parent_id {
+ // assert_eq!(self.items[&resolved].parent_id(), parent_id);
+ // }
}
}
+ /// Temporarily loan `Item` with the given `ItemId`. This provides means to
+ /// mutably borrow `Item` while having a reference to `BindgenContext`.
+ ///
+ /// `Item` with the given `ItemId` is removed from the context, given
+ /// closure is executed and then `Item` is placed back.
+ ///
+ /// # Panics
+ ///
+ /// Panics if attempt to resolve given `ItemId` inside the given
+ /// closure is made.
+ fn with_loaned_item<F, T>(&mut self, id: ItemId, f: F) -> T
+ where
+ F: (FnOnce(&BindgenContext, &mut Item) -> T)
+ {
+ let mut item = self.items.remove(&id).unwrap();
+
+ let result = f(self, &mut item);
+
+ let existing = self.items.insert(id, item);
+ assert!(existing.is_none());
+
+ result
+ }
+
/// Compute the bitfield allocation units for all `TypeKind::Comp` items we
/// parsed.
fn compute_bitfield_units(&mut self) {
@@ -763,22 +992,43 @@ impl BindgenContext {
let need_bitfield_allocation =
mem::replace(&mut self.need_bitfield_allocation, vec![]);
for id in need_bitfield_allocation {
- // To appease the borrow checker, we temporarily remove this item
- // from the context, and then replace it once we are done computing
- // its bitfield units. We will never try and resolve this
- // `TypeKind::Comp` item's id (which would now cause a panic) during
- // bitfield unit computation because it is a non-scalar by
- // definition, and non-scalar types may not be used as bitfields.
- let mut item = self.items.remove(&id).unwrap();
-
- item.kind_mut()
- .as_type_mut()
- .unwrap()
- .as_comp_mut()
- .unwrap()
- .compute_bitfield_units(&*self);
+ self.with_loaned_item(id, |ctx, item| {
+ item.kind_mut()
+ .as_type_mut()
+ .unwrap()
+ .as_comp_mut()
+ .unwrap()
+ .compute_bitfield_units(ctx);
+ });
+ }
+ }
- self.items.insert(id, item);
+ /// Assign a new generated name for each anonymous field.
+ fn deanonymize_fields(&mut self) {
+ let _t = self.timer("deanonymize_fields");
+
+ let comp_item_ids: Vec<ItemId> = self.items
+ .iter()
+ .filter_map(|(id, item)| {
+ if let Some(ty) = item.kind().as_type() {
+ if let Some(_comp) = ty.as_comp() {
+ return Some(id);
+ }
+ }
+ None
+ })
+ .cloned()
+ .collect();
+
+ for id in comp_item_ids {
+ self.with_loaned_item(id, |ctx, item| {
+ item.kind_mut()
+ .as_type_mut()
+ .unwrap()
+ .as_comp_mut()
+ .unwrap()
+ .deanonymize_fields(ctx);
+ });
}
}
@@ -825,19 +1075,19 @@ impl BindgenContext {
// We set this just after parsing the annotation. It's
// very unlikely, but this can happen.
if self.items.get(replacement).is_some() {
- replacements.push((*id, *replacement));
+ replacements.push((id.expect_type_id(self), replacement.expect_type_id(self)));
}
}
}
}
- for (id, replacement) in replacements {
- debug!("Replacing {:?} with {:?}", id, replacement);
+ for (id, replacement_id) in replacements {
+ debug!("Replacing {:?} with {:?}", id, replacement_id);
let new_parent = {
- let item = self.items.get_mut(&id).unwrap();
+ let item = self.items.get_mut(&id.into()).unwrap();
*item.kind_mut().as_type_mut().unwrap().kind_mut() =
- TypeKind::ResolvedTypeRef(replacement);
+ TypeKind::ResolvedTypeRef(replacement_id);
item.parent_id()
};
@@ -846,7 +1096,7 @@ impl BindgenContext {
//
// First, we'll make sure that its parent id is correct.
- let old_parent = self.resolve_item(replacement).parent_id();
+ let old_parent = self.resolve_item(replacement_id).parent_id();
if new_parent == old_parent {
// Same parent and therefore also same containing
// module. Nothing to do here.
@@ -854,7 +1104,7 @@ impl BindgenContext {
}
self.items
- .get_mut(&replacement)
+ .get_mut(&replacement_id.into())
.unwrap()
.set_parent_for_replacement(new_parent);
@@ -865,11 +1115,11 @@ impl BindgenContext {
let immut_self = &*self;
old_parent
.ancestors(immut_self)
- .chain(Some(immut_self.root_module))
+ .chain(Some(immut_self.root_module.into()))
.find(|id| {
let item = immut_self.resolve_item(*id);
item.as_module().map_or(false, |m| {
- m.children().contains(&replacement)
+ m.children().contains(&replacement_id.into())
})
})
};
@@ -883,7 +1133,7 @@ impl BindgenContext {
immut_self.resolve_item(*id).is_module()
})
};
- let new_module = new_module.unwrap_or(self.root_module);
+ let new_module = new_module.unwrap_or(self.root_module.into());
if new_module == old_module {
// Already in the correct module.
@@ -896,7 +1146,7 @@ impl BindgenContext {
.as_module_mut()
.unwrap()
.children_mut()
- .remove(&replacement);
+ .remove(&replacement_id.into());
self.items
.get_mut(&new_module)
@@ -904,28 +1154,24 @@ impl BindgenContext {
.as_module_mut()
.unwrap()
.children_mut()
- .insert(replacement);
+ .insert(replacement_id.into());
}
}
/// Enter the code generation phase, invoke the given callback `cb`, and
/// leave the code generation phase.
- pub fn gen<F, Out>(&mut self, cb: F) -> Out
+ pub(crate) fn gen<F, Out>(mut self, cb: F) -> (Out, BindgenOptions)
where
F: FnOnce(&Self) -> Out,
{
self.in_codegen = true;
- self.assert_no_dangling_references();
+ self.resolve_typerefs();
+ self.compute_bitfield_units();
+ self.process_replacements();
- if !self.collected_typerefs() {
- self.resolve_typerefs();
- self.compute_bitfield_units();
- self.process_replacements();
- }
+ self.deanonymize_fields();
- // And assert once again, because resolving type refs and processing
- // replacements both mutate the IR graph.
self.assert_no_dangling_references();
// Compute the whitelisted set after processing replacements and
@@ -939,6 +1185,7 @@ impl BindgenContext {
self.assert_every_item_in_a_module();
self.compute_has_vtable();
+ self.compute_sizedness();
self.compute_has_destructor();
self.find_used_template_parameters();
self.compute_cannot_derive_debug();
@@ -947,11 +1194,10 @@ impl BindgenContext {
self.compute_has_type_param_in_array();
self.compute_has_float();
self.compute_cannot_derive_hash();
- self.compute_cannot_derive_partialeq_or_eq();
+ self.compute_cannot_derive_partialord_partialeq_or_eq();
- let ret = cb(self);
- self.in_codegen = false;
- ret
+ let ret = cb(&self);
+ (ret, self.options)
}
/// When the `testing_only_extra_assertions` feature is enabled, this
@@ -999,7 +1245,7 @@ impl BindgenContext {
.through_type_aliases()
.resolve(self)
.id();
- id.ancestors(self).chain(Some(self.root_module)).any(
+ id.ancestors(self).chain(Some(self.root_module.into())).any(
|ancestor| {
debug!(
"Checking if {:?} is a child of {:?}",
@@ -1022,6 +1268,29 @@ impl BindgenContext {
}
}
+ /// Compute for every type whether it is sized or not, and whether it is
+ /// sized or not as a base class.
+ fn compute_sizedness(&mut self) {
+ let _t = self.timer("compute_sizedness");
+ assert!(self.sizedness.is_none());
+ self.sizedness = Some(analyze::<SizednessAnalysis>(self));
+ }
+
+ /// Look up whether the type with the given id is sized or not.
+ pub fn lookup_sizedness(&self, id: TypeId) -> SizednessResult {
+ assert!(
+ self.in_codegen_phase(),
+ "We only compute sizedness after we've entered codegen"
+ );
+
+ self.sizedness
+ .as_ref()
+ .unwrap()
+ .get(&id)
+ .cloned()
+ .unwrap_or(SizednessResult::ZeroSized)
+ }
+
/// Compute whether the type has vtable.
fn compute_has_vtable(&mut self) {
let _t = self.timer("compute_has_vtable");
@@ -1030,7 +1299,7 @@ impl BindgenContext {
}
/// Look up whether the item with `id` has vtable or not.
- pub fn lookup_item_id_has_vtable(&self, id: &ItemId) -> bool {
+ pub fn lookup_has_vtable(&self, id: TypeId) -> HasVtableResult {
assert!(
self.in_codegen_phase(),
"We only compute vtables when we enter codegen"
@@ -1038,7 +1307,12 @@ impl BindgenContext {
// Look up the computed value for whether the item with `id` has a
// vtable or not.
- self.have_vtable.as_ref().unwrap().contains(id)
+ self.have_vtable
+ .as_ref()
+ .unwrap()
+ .get(&id.into())
+ .cloned()
+ .unwrap_or(HasVtableResult::No)
}
/// Compute whether the type has a destructor.
@@ -1049,13 +1323,13 @@ impl BindgenContext {
}
/// Look up whether the item with `id` has a destructor.
- pub fn lookup_item_id_has_destructor(&self, id: &ItemId) -> bool {
+ pub fn lookup_has_destructor(&self, id: TypeId) -> bool {
assert!(
self.in_codegen_phase(),
"We only compute destructors when we enter codegen"
);
- self.have_destructor.as_ref().unwrap().contains(id)
+ self.have_destructor.as_ref().unwrap().contains(&id.into())
}
fn find_used_template_parameters(&mut self) {
@@ -1071,7 +1345,7 @@ impl BindgenContext {
used_params.entry(id).or_insert(
id.self_template_params(self).map_or(
Default::default(),
- |params| params.into_iter().collect(),
+ |params| params.into_iter().map(|p| p.into()).collect(),
),
);
}
@@ -1096,7 +1370,7 @@ impl BindgenContext {
pub fn uses_template_parameter(
&self,
item: ItemId,
- template_param: ItemId,
+ template_param: TypeId,
) -> bool {
assert!(
self.in_codegen_phase(),
@@ -1162,42 +1436,46 @@ impl BindgenContext {
Item::new(id, None, None, id, ItemKind::Module(module))
}
- /// Returns the target triple bindgen is running over.
- pub fn needs_mangling_hack(&self) -> bool {
- self.needs_mangling_hack
- }
-
/// Get the root module.
- pub fn root_module(&self) -> ItemId {
+ pub fn root_module(&self) -> ModuleId {
self.root_module
}
- /// Resolve the given `ItemId` as a type.
+ /// Resolve a type with the given id.
///
- /// Panics if there is no item for the given `ItemId` or if the resolved
+ /// Panics if there is no item for the given `TypeId` or if the resolved
/// item is not a `Type`.
- pub fn resolve_type(&self, type_id: ItemId) -> &Type {
- self.items.get(&type_id).unwrap().kind().expect_type()
+ pub fn resolve_type(&self, type_id: TypeId) -> &Type {
+ self.resolve_item(type_id).kind().expect_type()
+ }
+
+ /// Resolve a function with the given id.
+ ///
+ /// Panics if there is no item for the given `FunctionId` or if the resolved
+ /// item is not a `Function`.
+ pub fn resolve_func(&self, func_id: FunctionId) -> &Function {
+ self.resolve_item(func_id).kind().expect_function()
}
/// Resolve the given `ItemId` as a type, or `None` if there is no item with
/// the given id.
///
/// Panics if the id resolves to an item that is not a type.
- pub fn safe_resolve_type(&self, type_id: ItemId) -> Option<&Type> {
- self.items.get(&type_id).map(|t| t.kind().expect_type())
+ pub fn safe_resolve_type(&self, type_id: TypeId) -> Option<&Type> {
+ self.items.get(&type_id.into()).map(|t| t.kind().expect_type())
}
/// Resolve the given `ItemId` into an `Item`, or `None` if no such item
/// exists.
- pub fn resolve_item_fallible(&self, item_id: ItemId) -> Option<&Item> {
- self.items.get(&item_id)
+ pub fn resolve_item_fallible<Id: Into<ItemId>>(&self, id: Id) -> Option<&Item> {
+ self.items.get(&id.into())
}
/// Resolve the given `ItemId` into an `Item`.
///
/// Panics if the given id does not resolve to any item.
- pub fn resolve_item(&self, item_id: ItemId) -> &Item {
+ pub fn resolve_item<Id: Into<ItemId>>(&self, item_id: Id) -> &Item {
+ let item_id = item_id.into();
match self.items.get(&item_id) {
Some(item) => item,
None => panic!("Not an item: {:?}", item_id),
@@ -1205,7 +1483,7 @@ impl BindgenContext {
}
/// Get the current module.
- pub fn current_module(&self) -> ItemId {
+ pub fn current_module(&self) -> ModuleId {
self.current_module
}
@@ -1255,7 +1533,7 @@ impl BindgenContext {
|num_params| {
(
*canon_decl.cursor(),
- template_decl_id,
+ template_decl_id.into(),
num_params,
)
},
@@ -1329,10 +1607,10 @@ impl BindgenContext {
fn instantiate_template(
&mut self,
with_id: ItemId,
- template: ItemId,
+ template: TypeId,
ty: &clang::Type,
location: clang::Cursor,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
use clang_sys;
let num_expected_args = match self.resolve_type(template)
@@ -1389,7 +1667,7 @@ impl BindgenContext {
let ty = Item::from_ty_or_ref(
child.cur_type(),
*child,
- Some(template),
+ Some(template.into()),
self,
);
args.push(ty);
@@ -1411,7 +1689,7 @@ impl BindgenContext {
let ty = Item::from_ty_or_ref(
child.cur_type(),
*child,
- Some(template),
+ Some(template.into()),
self,
);
args.push(ty);
@@ -1429,14 +1707,16 @@ impl BindgenContext {
return None;
}
- let mut sub_args: Vec<_> = args.drain(
- args_len - num_expected_template_args..,
- ).collect();
+ let mut sub_args: Vec<_> = args
+ .drain(args_len - num_expected_template_args..)
+ .collect();
sub_args.reverse();
let sub_name = Some(template_decl_cursor.spelling());
let sub_inst = TemplateInstantiation::new(
- template_decl_id,
+ // This isn't guaranteed to be a type that we've
+ // already finished parsing yet.
+ template_decl_id.as_type_id_unchecked(),
sub_args,
);
let sub_kind =
@@ -1455,7 +1735,7 @@ impl BindgenContext {
sub_id,
None,
None,
- self.current_module,
+ self.current_module.into(),
ItemKind::Type(sub_ty),
);
@@ -1468,7 +1748,7 @@ impl BindgenContext {
self.add_item_to_module(&sub_item);
debug_assert!(sub_id == sub_item.id());
self.items.insert(sub_id, sub_item);
- args.push(sub_id);
+ args.push(sub_id.as_type_id_unchecked());
}
}
_ => {
@@ -1519,7 +1799,7 @@ impl BindgenContext {
with_id,
None,
None,
- self.current_module,
+ self.current_module.into(),
ItemKind::Type(ty),
);
@@ -1528,7 +1808,7 @@ impl BindgenContext {
self.add_item_to_module(&item);
debug_assert!(with_id == item.id());
self.items.insert(with_id, item);
- Some(with_id)
+ Some(with_id.as_type_id_unchecked())
}
/// If we have already resolved the type for the given type declaration,
@@ -1536,7 +1816,7 @@ impl BindgenContext {
pub fn get_resolved_type(
&self,
decl: &clang::CanonicalTypeDeclaration,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
self.types
.get(&TypeKey::Declaration(*decl.cursor()))
.or_else(|| {
@@ -1555,7 +1835,7 @@ impl BindgenContext {
parent_id: Option<ItemId>,
ty: &clang::Type,
location: Option<clang::Cursor>,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef};
debug!(
"builtin_or_resolved_ty: {:?}, {:?}, {:?}",
@@ -1626,10 +1906,10 @@ impl BindgenContext {
pub fn build_ty_wrapper(
&mut self,
with_id: ItemId,
- wrapped_id: ItemId,
+ wrapped_id: TypeId,
parent_id: Option<ItemId>,
ty: &clang::Type,
- ) -> ItemId {
+ ) -> TypeId {
let spelling = ty.spelling();
let is_const = ty.is_const();
let layout = ty.fallible_layout().ok();
@@ -1639,11 +1919,11 @@ impl BindgenContext {
with_id,
None,
None,
- parent_id.unwrap_or(self.current_module),
+ parent_id.unwrap_or(self.current_module.into()),
ItemKind::Type(ty),
);
self.add_builtin_item(item);
- with_id
+ with_id.as_type_id_unchecked()
}
/// Returns the next item id to be used for an item.
@@ -1653,7 +1933,7 @@ impl BindgenContext {
ret
}
- fn build_builtin_ty(&mut self, ty: &clang::Type) -> Option<ItemId> {
+ fn build_builtin_ty(&mut self, ty: &clang::Type) -> Option<TypeId> {
use clang_sys::*;
let type_kind = match ty.kind() {
CXType_NullPtr => TypeKind::NullPtr,
@@ -1703,9 +1983,9 @@ impl BindgenContext {
let ty = Type::new(Some(spelling), layout, type_kind, is_const);
let id = self.next_item_id();
let item =
- Item::new(id, None, None, self.root_module, ItemKind::Type(ty));
+ Item::new(id, None, None, self.root_module.into(), ItemKind::Type(ty));
self.add_builtin_item(item);
- Some(id)
+ Some(id.as_type_id_unchecked())
}
/// Get the current Clang translation unit that is being processed.
@@ -1767,7 +2047,8 @@ impl BindgenContext {
/// Is the item with the given `name` blacklisted? Or is the item with the given
/// `name` and `id` replaced by another type, and effectively blacklisted?
- pub fn blacklisted_by_name(&self, path: &[String], id: ItemId) -> bool {
+ pub fn blacklisted_by_name<Id: Into<ItemId>>(&self, path: &[String], id: Id) -> bool {
+ let id = id.into();
debug_assert!(
self.in_codegen_phase(),
"You're not supposed to call this yet"
@@ -1778,7 +2059,8 @@ impl BindgenContext {
/// Has the item with the given `name` and `id` been replaced by another
/// type?
- pub fn is_replaced_type(&self, path: &[String], id: ItemId) -> bool {
+ pub fn is_replaced_type<Id: Into<ItemId>>(&self, path: &[String], id: Id) -> bool {
+ let id = id.into();
match self.replacements.get(path) {
Some(replaced_by) if *replaced_by != id => true,
_ => false,
@@ -1795,7 +2077,7 @@ impl BindgenContext {
}
/// Get the options used to configure this bindgen context.
- pub fn options(&self) -> &BindgenOptions {
+ pub(crate) fn options(&self) -> &BindgenOptions {
&self.options
}
@@ -1862,7 +2144,7 @@ impl BindgenContext {
/// Given a CXCursor_Namespace cursor, return the item id of the
/// corresponding module, or create one on the fly.
- pub fn module(&mut self, cursor: clang::Cursor) -> ItemId {
+ pub fn module(&mut self, cursor: clang::Cursor) -> ModuleId {
use clang_sys::*;
assert_eq!(cursor.kind(), CXCursor_Namespace, "Be a nice person");
let cursor = cursor.canonical();
@@ -1878,11 +2160,12 @@ impl BindgenContext {
module_id,
None,
None,
- self.current_module,
+ self.current_module.into(),
ItemKind::Module(module),
);
- self.modules.insert(cursor, module.id());
+ let module_id = module.id().as_module_id_unchecked();
+ self.modules.insert(cursor, module_id);
self.add_item(module, None, None);
@@ -1891,7 +2174,7 @@ impl BindgenContext {
/// Start traversing the module with the given `module_id`, invoke the
/// callback `cb`, and then return to traversing the original module.
- pub fn with_module<F>(&mut self, module_id: ItemId, cb: F)
+ pub fn with_module<F>(&mut self, module_id: ModuleId, cb: F)
where
F: FnOnce(&mut Self),
{
@@ -2060,7 +2343,8 @@ impl BindgenContext {
/// Look up whether the item with `id` can
/// derive debug or not.
- pub fn lookup_item_id_can_derive_debug(&self, id: ItemId) -> bool {
+ pub fn lookup_can_derive_debug<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_debug when we enter codegen"
@@ -2083,7 +2367,8 @@ impl BindgenContext {
/// Look up whether the item with `id` can
/// derive default or not.
- pub fn lookup_item_id_can_derive_default(&self, id: ItemId) -> bool {
+ pub fn lookup_can_derive_default<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_default when we enter codegen"
@@ -2112,7 +2397,8 @@ impl BindgenContext {
/// Look up whether the item with `id` can
/// derive hash or not.
- pub fn lookup_item_id_can_derive_hash(&self, id: ItemId) -> bool {
+ pub fn lookup_can_derive_hash<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_debug when we enter codegen"
@@ -2123,32 +2409,30 @@ impl BindgenContext {
!self.cannot_derive_hash.as_ref().unwrap().contains(&id)
}
- /// Compute whether we can derive PartialEq. This method is also used in calculating
- /// whether we can derive Eq
- fn compute_cannot_derive_partialeq_or_eq(&mut self) {
- let _t = self.timer("compute_cannot_derive_partialeq_or_eq");
- assert!(self.cannot_derive_partialeq.is_none());
- if self.options.derive_partialeq || self.options.derive_eq {
- self.cannot_derive_partialeq = Some(analyze::<CannotDerivePartialEq>(self));
+ /// 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());
+ if self.options.derive_partialord || self.options.derive_partialeq || self.options.derive_eq {
+ self.cannot_derive_partialeq_or_partialord = Some(analyze::<CannotDerivePartialEqOrPartialOrd>(self));
}
}
- /// Look up whether the item with `id` can
- /// derive partialeq or not.
- pub fn lookup_item_id_can_derive_partialeq(&self, id: ItemId) -> bool {
+ /// Look up whether the item with `id` can derive `Partial{Eq,Ord}`.
+ pub fn lookup_can_derive_partialeq_or_partialord<Id: Into<ItemId>>(&self, id: Id) -> Option<CannotDeriveReason> {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
- "We only compute can_derive_debug when we enter codegen"
+ "We only compute can_derive_partialeq_or_partialord when we enter codegen"
);
// Look up the computed value for whether the item with `id` can
// derive partialeq or not.
- !self.cannot_derive_partialeq.as_ref().unwrap().contains(&id)
+ self.cannot_derive_partialeq_or_partialord.as_ref().unwrap().get(&id).cloned()
}
- /// Look up whether the item with `id` can
- /// derive copy or not.
- pub fn lookup_item_id_can_derive_copy(&self, id: ItemId) -> bool {
+ /// Look up whether the item with `id` can derive `Copy` or not.
+ pub fn lookup_can_derive_copy<Id: Into<ItemId>>(&self, id: Id) -> bool {
assert!(
self.in_codegen_phase(),
"We only compute can_derive_debug when we enter codegen"
@@ -2156,7 +2440,8 @@ impl BindgenContext {
// Look up the computed value for whether the item with `id` can
// derive `Copy` or not.
- !id.has_type_param_in_array(self) &&
+ let id = id.into();
+ !self.lookup_has_type_param_in_array(id) &&
!self.cannot_derive_copy.as_ref().unwrap().contains(&id)
}
@@ -2169,7 +2454,7 @@ impl BindgenContext {
}
/// Look up whether the item with `id` has type parameter in array or not.
- pub fn lookup_item_id_has_type_param_in_array(&self, id: &ItemId) -> bool {
+ pub fn lookup_has_type_param_in_array<Id: Into<ItemId>>(&self, id: Id) -> bool {
assert!(
self.in_codegen_phase(),
"We only compute has array when we enter codegen"
@@ -2177,26 +2462,44 @@ impl BindgenContext {
// Look up the computed value for whether the item with `id` has
// type parameter in array or not.
- self.has_type_param_in_array.as_ref().unwrap().contains(id)
+ self.has_type_param_in_array.as_ref().unwrap().contains(&id.into())
}
/// Compute whether the type has float.
fn compute_has_float(&mut self) {
let _t = self.timer("compute_has_float");
assert!(self.has_float.is_none());
- if self.options.derive_eq {
+ if self.options.derive_eq || self.options.derive_ord {
self.has_float = Some(analyze::<HasFloat>(self));
}
}
/// Look up whether the item with `id` has array or not.
- pub fn lookup_item_id_has_float(&self, id: &ItemId) -> bool {
+ pub fn lookup_has_float<Id: Into<ItemId>>(&self, id: Id) -> bool {
assert!(self.in_codegen_phase(),
"We only compute has float when we enter codegen");
// Look up the computed value for whether the item with `id` has
// float or not.
- self.has_float.as_ref().unwrap().contains(id)
+ self.has_float.as_ref().unwrap().contains(&id.into())
+ }
+
+ /// Check if `--no-partialeq` flag is enabled for this item.
+ pub fn no_partialeq_by_name(&self, item: &Item) -> bool {
+ let name = item.canonical_path(self)[1..].join("::");
+ self.options().no_partialeq_types.matches(&name)
+ }
+
+ /// Check if `--no-copy` flag is enabled for this item.
+ pub fn no_copy_by_name(&self, item: &Item) -> bool {
+ let name = item.canonical_path(self)[1..].join("::");
+ self.options().no_copy_types.matches(&name)
+ }
+
+ /// Chech if `--no-hash` flag is enabled for this item.
+ pub fn no_hash_by_name(&self, item: &Item) -> bool {
+ let name = item.canonical_path(self)[1..].join("::");
+ self.options().no_hash_types.matches(&name)
}
}
@@ -2215,15 +2518,19 @@ impl ItemId {
}
}
-impl From<ItemId> for ItemResolver {
- fn from(id: ItemId) -> ItemResolver {
+impl<T> From<T> for ItemResolver
+where
+ T: Into<ItemId>
+{
+ fn from(id: T) -> ItemResolver {
ItemResolver::new(id)
}
}
impl ItemResolver {
/// Construct a new `ItemResolver` from the given id.
- pub fn new(id: ItemId) -> ItemResolver {
+ pub fn new<Id: Into<ItemId>>(id: Id) -> ItemResolver {
+ let id = id.into();
ItemResolver {
id: id,
through_type_refs: false,
@@ -2254,14 +2561,14 @@ impl ItemResolver {
match ty_kind {
Some(&TypeKind::ResolvedTypeRef(next_id))
if self.through_type_refs => {
- id = next_id;
+ id = next_id.into();
}
// We intentionally ignore template aliases here, as they are
// more complicated, and don't represent a simple renaming of
// some type.
Some(&TypeKind::Alias(next_id))
if self.through_type_aliases => {
- id = next_id;
+ id = next_id.into();
}
_ => return item,
}
@@ -2273,6 +2580,8 @@ impl ItemResolver {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PartialType {
decl: Cursor,
+ // Just an ItemId, and not a TypeId, because we haven't finished this type
+ // yet, so there's still time for things to go wrong.
id: ItemId,
}
@@ -2302,7 +2611,7 @@ impl TemplateParameters for PartialType {
fn self_template_params(
&self,
_ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
// Maybe at some point we will eagerly parse named types, but for now we
// don't and this information is unavailable.
None
diff --git a/src/ir/derive.rs b/src/ir/derive.rs
index 909d5e42..52e61133 100644
--- a/src/ir/derive.rs
+++ b/src/ir/derive.rs
@@ -1,27 +1,32 @@
//! Traits for determining whether we can derive traits for a thing or not.
+//!
+//! 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.
+//!
+//! 2. A "normal" version, whose implementations simply query the results of a
+//! fix point analysis.
+//!
+//! The former is used by the analyses when creating the results queried by the
+//! second.
use super::context::BindgenContext;
/// A trait that encapsulates the logic for whether or not we can derive `Debug`
/// for a given thing.
-///
-/// This should ideally be a no-op that just returns `true`, but instead needs
-/// to be a recursive method that checks whether all the proper members can
-/// derive debug or not, because of the limit rust has on 32 items as max in the
-/// array.
pub trait CanDeriveDebug {
/// Return `true` if `Debug` can be derived for this thing, `false`
/// otherwise.
fn can_derive_debug(&self, ctx: &BindgenContext) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `Debug`.
-/// The difference between this trait and the CanDeriveDebug is that the type
-/// implementing this trait cannot use recursion or lookup result from fix point
-/// analysis. It's a helper trait for fix point analysis.
+/// A trait that encapsulates the logic for whether or not we can trivially
+/// derive `Debug` without looking at any other types or the results of a fix
+/// point analysis. This is a helper trait for the fix point analysis.
pub trait CanTriviallyDeriveDebug {
- /// Return `true` if `Debug` can be derived for this thing, `false`
- /// otherwise.
+ /// Return `true` if `Debug` can trivially be derived for this thing,
+ /// `false` otherwise.
fn can_trivially_derive_debug(&self) -> bool;
}
@@ -33,97 +38,106 @@ pub trait CanDeriveCopy<'a> {
fn can_derive_copy(&'a self, ctx: &'a BindgenContext) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `Copy`.
-/// The difference between this trait and the CanDeriveCopy is that the type
-/// implementing this trait cannot use recursion or lookup result from fix point
-/// analysis. It's a helper trait for fix point analysis.
+/// A trait that encapsulates the logic for whether or not we can trivially
+/// derive `Copy` without looking at any other types or results of fix point
+/// analsyses. This is a helper trait for fix point analysis.
pub trait CanTriviallyDeriveCopy {
- /// Return `true` if `Copy` can be derived for this thing, `false`
+ /// Return `true` if `Copy` can be trivially derived for this thing, `false`
/// otherwise.
fn can_trivially_derive_copy(&self) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `Default`
-/// for a given thing.
-///
-/// This should ideally be a no-op that just returns `true`, but instead needs
-/// to be a recursive method that checks whether all the proper members can
-/// derive default or not, because of the limit rust has on 32 items as max in the
-/// array.
+/// A trait that encapsulates the logic for whether or not we can derive
+/// `Default` for a given thing.
pub trait CanDeriveDefault {
/// Return `true` if `Default` can be derived for this thing, `false`
/// otherwise.
fn can_derive_default(&self, ctx: &BindgenContext) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `Default`.
-/// The difference between this trait and the CanDeriveDefault is that the type
-/// implementing this trait cannot use recursion or lookup result from fix point
-/// analysis. It's a helper trait for fix point analysis.
+/// A trait that encapsulates the logic for whether or not we can trivially
+/// derive `Default` without looking at any other types or results of fix point
+/// analyses. This is a helper trait for the fix point analysis.
pub trait CanTriviallyDeriveDefault {
- /// Return `true` if `Default` can be derived for this thing, `false`
+ /// Return `true` if `Default` can trivially derived for this thing, `false`
/// otherwise.
fn can_trivially_derive_default(&self) -> bool;
}
/// A trait that encapsulates the logic for whether or not we can derive `Hash`
/// for a given thing.
-///
-/// This should ideally be a no-op that just returns `true`, but instead needs
-/// to be a recursive method that checks whether all the proper members can
-/// derive default or not, because of the limit rust has on 32 items as max in the
-/// array.
pub trait CanDeriveHash {
- /// Return `true` if `Default` can be derived for this thing, `false`
+ /// Return `true` if `Hash` can be derived for this thing, `false`
/// otherwise.
fn can_derive_hash(&self, ctx: &BindgenContext) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `PartialEq`
-/// for a given thing.
-///
-/// This should ideally be a no-op that just returns `true`, but instead needs
-/// to be a recursive method that checks whether all the proper members can
-/// derive default or not, because of the limit rust has on 32 items as max in the
-/// array.
+/// A trait that encapsulates the logic for whether or not we can derive
+/// `PartialEq` for a given thing.
pub trait CanDerivePartialEq {
- /// Return `true` if `Default` can be derived for this thing, `false`
+ /// Return `true` if `PartialEq` can be derived for this thing, `false`
/// otherwise.
fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool;
}
+/// A trait that encapsulates the logic for whether or not we can derive
+/// `PartialOrd` for a given thing.
+pub trait CanDerivePartialOrd {
+ /// Return `true` if `PartialOrd` can be derived for this thing, `false`
+ /// otherwise.
+ fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool;
+}
+
/// A trait that encapsulates the logic for whether or not we can derive `Eq`
/// for a given thing.
-///
-/// This should ideally be a no-op that just returns `true`, but instead needs
-/// to be a recursive method that checks whether all the proper members can
-/// derive eq or not, because of the limit rust has on 32 items as max in the
-/// array.
pub trait CanDeriveEq {
+ /// Return `true` if `Eq` can be derived for this thing, `false` otherwise.
+ fn can_derive_eq(&self, ctx: &BindgenContext) -> bool;
+}
- /// Return `true` if `Eq` can be derived for this thing, `false`
- /// otherwise.
- fn can_derive_eq(&self,
- ctx: &BindgenContext)
- -> bool;
+/// A trait that encapsulates the logic for whether or not we can derive `Ord`
+/// for a given thing.
+pub trait CanDeriveOrd {
+ /// Return `true` if `Ord` can be derived for this thing, `false` otherwise.
+ fn can_derive_ord(&self, ctx: &BindgenContext) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `Hash`.
-/// The difference between this trait and the CanDeriveHash is that the type
-/// implementing this trait cannot use recursion or lookup result from fix point
-/// analysis. It's a helper trait for fix point analysis.
+/// A trait that encapsulates the logic for whether or not we can derive `Hash`
+/// without looking at any other types or the results of any fix point
+/// analyses. This is a helper trait for the fix point analysis.
pub trait CanTriviallyDeriveHash {
- /// Return `true` if `Hash` can be derived for this thing, `false`
+ /// Return `true` if `Hash` can trivially be derived for this thing, `false`
/// otherwise.
fn can_trivially_derive_hash(&self) -> bool;
}
-/// A trait that encapsulates the logic for whether or not we can derive `PartialEq`.
-/// The difference between this trait and the CanDerivePartialEq is that the type
-/// implementing this trait cannot use recursion or lookup result from fix point
-/// analysis. It's a helper trait for fix point analysis.
-pub trait CanTriviallyDerivePartialEq {
- /// Return `true` if `PartialEq` can be derived for this thing, `false`
- /// otherwise.
- fn can_trivially_derive_partialeq(&self) -> bool;
+/// A trait that encapsulates the logic for whether or not we can trivially
+/// derive `PartialEq` or `PartialOrd` without looking at any other types or
+/// results of fix point analyses. This is a helper for the fix point analysis.
+pub trait CanTriviallyDerivePartialEqOrPartialOrd {
+ /// Return `true` if `PartialEq` or `PartialOrd` can trivially be derived
+ /// for this thing, `false` otherwise.
+ fn can_trivially_derive_partialeq_or_partialord(&self) -> CanDerive;
+}
+
+/// Reason why exactly we cannot automatically derive a trait.
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum CannotDeriveReason {
+ /// The only thing that stops us from automatically deriving is that
+ /// array with more than maximum number of elements is used.
+ ///
+ /// This means we probably can "manually" implement such trait.
+ ArrayTooLarge,
+
+ /// Any other reason.
+ Other,
+}
+
+/// Whether it is possible or not to derive trait automatically.
+pub enum CanDerive {
+ /// Yes, we can!
+ Yes,
+
+ /// No, we cannot. Contains reason why exactly we can't derive.
+ No(CannotDeriveReason)
}
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs
index dc56f64a..d0968515 100644
--- a/src/ir/enum_ty.rs
+++ b/src/ir/enum_ty.rs
@@ -1,6 +1,6 @@
//! Intermediate representation for C/C++ enumerations.
-use super::context::{BindgenContext, ItemId};
+use super::context::{BindgenContext, TypeId};
use super::item::Item;
use super::ty::TypeKind;
use clang;
@@ -27,7 +27,7 @@ pub struct Enum {
///
/// It's `None` if the enum is a forward declaration and isn't defined
/// anywhere else, see `tests/headers/func_ptr_in_struct.h`.
- repr: Option<ItemId>,
+ repr: Option<TypeId>,
/// The different variants, with explicit values.
variants: Vec<EnumVariant>,
@@ -35,15 +35,15 @@ pub struct Enum {
impl Enum {
/// Construct a new `Enum` with the given representation and variants.
- pub fn new(repr: Option<ItemId>, variants: Vec<EnumVariant>) -> Self {
+ pub fn new(repr: Option<TypeId>, variants: Vec<EnumVariant>) -> Self {
Enum {
- repr: repr,
- variants: variants,
+ repr,
+ variants,
}
}
/// Get this enumeration's representation.
- pub fn repr(&self) -> Option<ItemId> {
+ pub fn repr(&self) -> Option<TypeId> {
self.repr
}
@@ -204,10 +204,10 @@ impl EnumVariant {
custom_behavior: Option<EnumVariantCustomBehavior>,
) -> Self {
EnumVariant {
- name: name,
- comment: comment,
- val: val,
- custom_behavior: custom_behavior,
+ name,
+ comment,
+ val,
+ custom_behavior,
}
}
diff --git a/src/ir/function.rs b/src/ir/function.rs
index b08824af..60a7effd 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -1,7 +1,7 @@
//! Intermediate representation for C/C++ functions and methods.
use super::comp::MethodKind;
-use super::context::{BindgenContext, ItemId};
+use super::context::{BindgenContext, TypeId};
use super::dot::DotAttributes;
use super::item::Item;
use super::traversal::{EdgeKind, Trace, Tracer};
@@ -9,7 +9,7 @@ use super::ty::TypeKind;
use clang;
use clang_sys::{self, CXCallingConv};
use ir::derive::{CanTriviallyDeriveDebug, CanTriviallyDeriveHash,
- CanTriviallyDerivePartialEq};
+ CanTriviallyDerivePartialEqOrPartialOrd, CanDerive, CannotDeriveReason};
use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
use quote;
use std::io;
@@ -49,6 +49,15 @@ impl FunctionKind {
}
}
+/// The style of linkage
+#[derive(Debug, Clone, Copy)]
+pub enum Linkage {
+ /// Externally visible and can be linked against
+ External,
+ /// Not exposed externally. 'static inline' functions will have this kind of linkage
+ Internal
+}
+
/// A function declaration, with a signature, arguments, and argument names.
///
/// The argument names vector must be the same length as the ones in the
@@ -62,13 +71,16 @@ pub struct Function {
mangled_name: Option<String>,
/// The id pointing to the current function signature.
- signature: ItemId,
+ signature: TypeId,
/// The doc comment on the function, if any.
comment: Option<String>,
/// The kind of function this is.
kind: FunctionKind,
+
+ /// The linkage of the function.
+ linkage: Linkage,
}
impl Function {
@@ -76,16 +88,18 @@ impl Function {
pub fn new(
name: String,
mangled_name: Option<String>,
- sig: ItemId,
+ signature: TypeId,
comment: Option<String>,
kind: FunctionKind,
+ linkage: Linkage
) -> Self {
Function {
- name: name,
- mangled_name: mangled_name,
- signature: sig,
- comment: comment,
- kind: kind,
+ name,
+ mangled_name,
+ signature,
+ comment,
+ kind,
+ linkage,
}
}
@@ -99,8 +113,8 @@ impl Function {
self.mangled_name.as_ref().map(|n| &**n)
}
- /// Get this function's signature.
- pub fn signature(&self) -> ItemId {
+ /// Get this function's signature type.
+ pub fn signature(&self) -> TypeId {
self.signature
}
@@ -108,6 +122,12 @@ impl Function {
pub fn kind(&self) -> FunctionKind {
self.kind
}
+
+ /// Get this function's linkage.
+ pub fn linkage(&self) -> Linkage {
+ self.linkage
+ }
+
}
impl DotAttributes for Function {
@@ -142,6 +162,8 @@ pub enum Abi {
Stdcall,
/// The "fastcall" ABI.
Fastcall,
+ /// The "thiscall" ABI.
+ ThisCall,
/// The "aapcs" ABI.
Aapcs,
/// The "win64" ABI.
@@ -166,6 +188,7 @@ impl quote::ToTokens for Abi {
Abi::C => quote! { "C" },
Abi::Stdcall => quote! { "stdcall" },
Abi::Fastcall => quote! { "fastcall" },
+ Abi::ThisCall => quote! { "thiscall" },
Abi::Aapcs => quote! { "aapcs" },
Abi::Win64 => quote! { "win64" },
Abi::Unknown(cc) => panic!(
@@ -180,11 +203,11 @@ impl quote::ToTokens for Abi {
#[derive(Debug)]
pub struct FunctionSig {
/// The return type of the function.
- return_type: ItemId,
+ return_type: TypeId,
/// The type of the arguments, optionally with the name of the argument when
/// declared.
- argument_types: Vec<(Option<String>, ItemId)>,
+ argument_types: Vec<(Option<String>, TypeId)>,
/// Whether this function is variadic.
is_variadic: bool,
@@ -200,29 +223,13 @@ fn get_abi(cc: CXCallingConv) -> Abi {
CXCallingConv_C => Abi::C,
CXCallingConv_X86StdCall => Abi::Stdcall,
CXCallingConv_X86FastCall => Abi::Fastcall,
+ CXCallingConv_X86ThisCall => Abi::ThisCall,
CXCallingConv_AAPCS => Abi::Aapcs,
CXCallingConv_X86_64Win64 => Abi::Win64,
other => Abi::Unknown(other),
}
}
-fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) {
- if ctx.needs_mangling_hack() {
- match symbol.chars().next().unwrap() {
- // Stripping leading underscore for all names on Darwin and
- // C linkage functions on Win32.
- '_' => {
- symbol.remove(0);
- }
- // Stop Rust from prepending underscore for variables on Win32.
- '?' => {
- symbol.insert(0, '\x01');
- }
- _ => {}
- }
- }
-}
-
/// Get the mangled name for the cursor's referent.
pub fn cursor_mangling(
ctx: &BindgenContext,
@@ -241,8 +248,7 @@ pub fn cursor_mangling(
}
if let Ok(mut manglings) = cursor.cxx_manglings() {
- if let Some(mut m) = manglings.pop() {
- mangling_hack_if_needed(ctx, &mut m);
+ if let Some(m) = manglings.pop() {
return Some(m);
}
}
@@ -252,8 +258,6 @@ pub fn cursor_mangling(
return None;
}
- mangling_hack_if_needed(ctx, &mut mangling);
-
if cursor.kind() == clang_sys::CXCursor_Destructor {
// With old (3.8-) libclang versions, and the Itanium ABI, clang returns
// the "destructor group 0" symbol, which means that it'll try to free
@@ -287,8 +291,8 @@ pub fn cursor_mangling(
impl FunctionSig {
/// Construct a new function signature.
pub fn new(
- return_type: ItemId,
- arguments: Vec<(Option<String>, ItemId)>,
+ return_type: TypeId,
+ arguments: Vec<(Option<String>, TypeId)>,
is_variadic: bool,
abi: Abi,
) -> Self {
@@ -384,6 +388,10 @@ impl FunctionSig {
if !is_static && !is_virtual {
let class = Item::parse(cursor.semantic_parent(), None, ctx)
.expect("Expected to parse the class");
+ // The `class` most likely is not finished parsing yet, so use
+ // the unchecked variant.
+ let class = class.as_type_id_unchecked();
+
let ptr =
Item::builtin_type(TypeKind::Pointer(class), is_const, ctx);
args.insert(0, (Some("this".into()), ptr));
@@ -412,16 +420,16 @@ impl FunctionSig {
warn!("Unknown calling convention: {:?}", call_conv);
}
- Ok(Self::new(ret, args, ty.is_variadic(), abi))
+ Ok(Self::new(ret.into(), args, ty.is_variadic(), abi))
}
/// Get this function signature's return type.
- pub fn return_type(&self) -> ItemId {
+ pub fn return_type(&self) -> TypeId {
self.return_type
}
/// Get this function signature's argument (name, type) pairs.
- pub fn argument_types(&self) -> &[(Option<String>, ItemId)] {
+ pub fn argument_types(&self) -> &[(Option<String>, TypeId)] {
&self.argument_types
}
@@ -437,6 +445,26 @@ impl FunctionSig {
// variadic functions without an initial argument.
self.is_variadic && !self.argument_types.is_empty()
}
+
+ /// Are function pointers with this signature able to derive Rust traits?
+ /// Rust only supports deriving traits for function pointers with a limited
+ /// number of parameters and a couple ABIs.
+ ///
+ /// For more details, see:
+ ///
+ /// * https://github.com/rust-lang-nursery/rust-bindgen/issues/547,
+ /// * https://github.com/rust-lang/rust/issues/38848,
+ /// * and https://github.com/rust-lang/rust/issues/40158
+ pub fn function_pointers_can_derive(&self) -> bool {
+ if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
+ return false;
+ }
+
+ match self.abi {
+ Abi::C | Abi::Unknown(..) => true,
+ _ => false,
+ }
+ }
}
impl ClangSubItemParser for Function {
@@ -469,11 +497,11 @@ impl ClangSubItemParser for Function {
}
let linkage = cursor.linkage();
- if linkage != CXLinkage_External &&
- linkage != CXLinkage_UniqueExternal
- {
- return Err(ParseError::Continue);
- }
+ let linkage = match linkage {
+ CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External,
+ CXLinkage_Internal => Linkage::Internal,
+ _ => return Err(ParseError::Continue)
+ };
// Grab the signature using Item::from_ty.
let sig =
@@ -503,7 +531,7 @@ impl ClangSubItemParser for Function {
let comment = cursor.raw_comment();
- let function = Self::new(name, mangled_name, sig, comment, kind);
+ let function = Self::new(name, mangled_name, sig, comment, kind, linkage);
Ok(ParseResult::New(function, Some(cursor)))
}
}
@@ -515,56 +543,35 @@ impl Trace for FunctionSig {
where
T: Tracer,
{
- tracer.visit_kind(self.return_type(), EdgeKind::FunctionReturn);
+ tracer.visit_kind(self.return_type().into(), EdgeKind::FunctionReturn);
for &(_, ty) in self.argument_types() {
- tracer.visit_kind(ty, EdgeKind::FunctionParameter);
+ tracer.visit_kind(ty.into(), EdgeKind::FunctionParameter);
}
}
}
-// Function pointers follow special rules, see:
-//
-// https://github.com/rust-lang-nursery/rust-bindgen/issues/547,
-// https://github.com/rust-lang/rust/issues/38848,
-// and https://github.com/rust-lang/rust/issues/40158
-//
-// Note that copy is always derived, so we don't need to implement it.
impl CanTriviallyDeriveDebug for FunctionSig {
fn can_trivially_derive_debug(&self) -> bool {
- if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
- return false;
- }
-
- match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
- }
+ self.function_pointers_can_derive()
}
}
impl CanTriviallyDeriveHash for FunctionSig {
fn can_trivially_derive_hash(&self) -> bool {
- if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
- return false;
- }
-
- match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
- }
+ self.function_pointers_can_derive()
}
}
-impl CanTriviallyDerivePartialEq for FunctionSig {
- fn can_trivially_derive_partialeq(&self) -> bool {
+impl CanTriviallyDerivePartialEqOrPartialOrd for FunctionSig {
+ fn can_trivially_derive_partialeq_or_partialord(&self) -> CanDerive {
if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT {
- return false;
+ return CanDerive::No(CannotDeriveReason::Other);
}
match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
+ Abi::C | Abi::Unknown(..) => CanDerive::Yes,
+ _ => CanDerive::No(CannotDeriveReason::Other),
}
}
}
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 2a4df7aa..9ed7267d 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -1,12 +1,13 @@
//! Bindgen's core intermediate representation type.
-use super::analysis::HasVtable;
+use super::analysis::{HasVtable, HasVtableResult, Sizedness, SizednessResult};
use super::annotations::Annotations;
use super::comment;
use super::comp::MethodKind;
-use super::context::{BindgenContext, ItemId, PartialType};
+use super::context::{BindgenContext, ItemId, PartialType, TypeId};
use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault,
- CanDeriveHash, CanDerivePartialEq, CanDeriveEq};
+ CanDeriveHash, CanDerivePartialOrd, CanDeriveOrd,
+ CanDerivePartialEq, CanDeriveEq};
use super::dot::DotAttributes;
use super::function::{Function, FunctionKind};
use super::item_kind::ItemKind;
@@ -110,7 +111,7 @@ cfg_if! {
DebugOnlyItemSet
}
- fn contains(&self,_id: &ItemId) -> bool {
+ fn contains(&self, _id: &ItemId) -> bool {
false
}
@@ -127,9 +128,9 @@ pub struct ItemAncestorsIter<'a> {
}
impl<'a> ItemAncestorsIter<'a> {
- fn new(ctx: &'a BindgenContext, item: ItemId) -> Self {
+ fn new<Id: Into<ItemId>>(ctx: &'a BindgenContext, id: Id) -> Self {
ItemAncestorsIter {
- item: item,
+ item: id.into(),
ctx: ctx,
seen: DebugOnlyItemSet::new(),
}
@@ -155,15 +156,17 @@ impl<'a> Iterator for ItemAncestorsIter<'a> {
}
}
-impl AsTemplateParam for ItemId {
+impl<T> AsTemplateParam for T
+where
+ T: Copy + Into<ItemId> {
type Extra = ();
fn as_template_param(
&self,
ctx: &BindgenContext,
_: &(),
- ) -> Option<ItemId> {
- ctx.resolve_item(*self).as_template_param(ctx, &())
+ ) -> Option<TypeId> {
+ ctx.resolve_item((*self).into()).as_template_param(ctx, &())
}
}
@@ -174,7 +177,7 @@ impl AsTemplateParam for Item {
&self,
ctx: &BindgenContext,
_: &(),
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
self.kind.as_template_param(ctx, self)
}
}
@@ -186,7 +189,7 @@ impl AsTemplateParam for ItemKind {
&self,
ctx: &BindgenContext,
item: &Item,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
match *self {
ItemKind::Type(ref ty) => ty.as_template_param(ctx, item),
ItemKind::Module(..) |
@@ -196,8 +199,10 @@ impl AsTemplateParam for ItemKind {
}
}
-// Pure convenience
-impl ItemCanonicalName for ItemId {
+impl<T> ItemCanonicalName for T
+where
+ T: Copy + Into<ItemId>
+{
fn canonical_name(&self, ctx: &BindgenContext) -> String {
debug_assert!(
ctx.in_codegen_phase(),
@@ -207,7 +212,10 @@ impl ItemCanonicalName for ItemId {
}
}
-impl ItemCanonicalPath for ItemId {
+impl<T> ItemCanonicalPath for T
+ where
+ T: Copy + Into<ItemId>
+{
fn namespace_aware_canonical_path(
&self,
ctx: &BindgenContext,
@@ -228,7 +236,10 @@ impl ItemCanonicalPath for ItemId {
}
}
-impl ItemAncestors for ItemId {
+impl<T> ItemAncestors for T
+where
+ T: Copy + Into<ItemId>
+{
fn ancestors<'a>(
&self,
ctx: &'a BindgenContext,
@@ -246,7 +257,10 @@ impl ItemAncestors for Item {
}
}
-impl Trace for ItemId {
+impl<Id> Trace for Id
+where
+ Id: Copy + Into<ItemId>
+{
type Extra = ();
fn trace<T>(&self, ctx: &BindgenContext, tracer: &mut T, extra: &())
@@ -285,10 +299,10 @@ impl Trace for Item {
ItemKind::Function(ref fun) => {
// Just the same way, it has not real meaning for a function to
// be opaque, so we trace across it.
- tracer.visit(fun.signature());
+ tracer.visit(fun.signature().into());
}
ItemKind::Var(ref var) => {
- tracer.visit_kind(var.ty(), EdgeKind::VarType);
+ tracer.visit_kind(var.ty().into(), EdgeKind::VarType);
}
ItemKind::Module(_) => {
// Module -> children edges are "weak", and we do not want to
@@ -306,42 +320,57 @@ impl Trace for Item {
impl CanDeriveDebug for Item {
fn can_derive_debug(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_debug &&
- ctx.lookup_item_id_can_derive_debug(self.id())
+ ctx.lookup_can_derive_debug(self.id())
}
}
impl CanDeriveDefault for Item {
fn can_derive_default(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_default &&
- ctx.lookup_item_id_can_derive_default(self.id())
+ ctx.lookup_can_derive_default(self.id())
}
}
impl<'a> CanDeriveCopy<'a> for Item {
fn can_derive_copy(&self, ctx: &BindgenContext) -> bool {
- ctx.lookup_item_id_can_derive_copy(self.id())
+ ctx.lookup_can_derive_copy(self.id())
}
}
impl CanDeriveHash for Item {
fn can_derive_hash(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_hash &&
- ctx.lookup_item_id_can_derive_hash(self.id())
+ ctx.lookup_can_derive_hash(self.id())
+ }
+}
+
+impl CanDerivePartialOrd for Item {
+ fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool {
+ ctx.options().derive_partialord &&
+ ctx.lookup_can_derive_partialeq_or_partialord(self.id()).is_none()
}
}
impl CanDerivePartialEq for Item {
fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_partialeq &&
- ctx.lookup_item_id_can_derive_partialeq(self.id())
+ ctx.lookup_can_derive_partialeq_or_partialord(self.id()).is_none()
}
}
impl CanDeriveEq for Item {
fn can_derive_eq(&self, ctx: &BindgenContext) -> bool {
ctx.options().derive_eq &&
- ctx.lookup_item_id_can_derive_partialeq(self.id()) &&
- !ctx.lookup_item_id_has_float(&self.id())
+ ctx.lookup_can_derive_partialeq_or_partialord(self.id()).is_none() &&
+ !ctx.lookup_has_float(self.id())
+ }
+}
+
+impl CanDeriveOrd for Item {
+ fn can_derive_ord(&self, ctx: &BindgenContext) -> bool {
+ ctx.options().derive_ord &&
+ ctx.lookup_can_derive_partialeq_or_partialord(self.id()).is_none() &&
+ !ctx.lookup_has_float(self.id())
}
}
@@ -433,12 +462,12 @@ impl Item {
with_id: ItemId,
ty: &clang::Type,
ctx: &mut BindgenContext,
- ) -> ItemId {
+ ) -> TypeId {
let ty = Opaque::from_clang_ty(ty);
let kind = ItemKind::Type(ty);
- let parent = ctx.root_module();
+ let parent = ctx.root_module().into();
ctx.add_item(Item::new(with_id, None, None, parent, kind), None, None);
- with_id
+ with_id.as_type_id_unchecked()
}
/// Get this `Item`'s identifier.
@@ -456,8 +485,8 @@ impl Item {
/// Set this item's parent id.
///
/// This is only used so replacements get generated in the proper module.
- pub fn set_parent_for_replacement(&mut self, id: ItemId) {
- self.parent_id = id;
+ pub fn set_parent_for_replacement<Id: Into<ItemId>>(&mut self, id: Id) {
+ self.parent_id = id.into();
}
/// Returns the depth this item is indented to.
@@ -936,7 +965,10 @@ impl Item {
}
}
-impl IsOpaque for ItemId {
+impl<T> IsOpaque for T
+where
+ T: Copy + Into<ItemId>
+{
type Extra = ();
fn is_opaque(&self, ctx: &BindgenContext, _: &()) -> bool {
@@ -944,7 +976,7 @@ impl IsOpaque for ItemId {
ctx.in_codegen_phase(),
"You're not supposed to call this yet"
);
- ctx.resolve_item(*self).is_opaque(ctx, &())
+ ctx.resolve_item((*self).into()).is_opaque(ctx, &())
}
}
@@ -962,25 +994,66 @@ impl IsOpaque for Item {
}
}
-impl HasVtable for ItemId {
+impl<T> HasVtable for T
+where
+ T: Copy + Into<ItemId>
+{
fn has_vtable(&self, ctx: &BindgenContext) -> bool {
- ctx.lookup_item_id_has_vtable(self)
+ let id: ItemId = (*self).into();
+ id.as_type_id(ctx)
+ .map_or(false, |id| match ctx.lookup_has_vtable(id) {
+ HasVtableResult::No => false,
+ _ => true,
+ })
+ }
+
+ fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool {
+ let id: ItemId = (*self).into();
+ id.as_type_id(ctx)
+ .map_or(false, |id| match ctx.lookup_has_vtable(id) {
+ HasVtableResult::SelfHasVtable => true,
+ _ => false,
+ })
}
}
impl HasVtable for Item {
fn has_vtable(&self, ctx: &BindgenContext) -> bool {
- ctx.lookup_item_id_has_vtable(&self.id())
+ self.id().has_vtable(ctx)
+ }
+
+ fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool {
+ self.id().has_vtable_ptr(ctx)
+ }
+}
+
+impl<T> Sizedness for T
+where
+ T: Copy + Into<ItemId>
+{
+ fn sizedness(&self, ctx: &BindgenContext) -> SizednessResult {
+ let id: ItemId = (*self).into();
+ id.as_type_id(ctx)
+ .map_or(SizednessResult::default(), |id| ctx.lookup_sizedness(id))
+ }
+}
+
+impl Sizedness for Item {
+ fn sizedness(&self, ctx: &BindgenContext) -> SizednessResult {
+ self.id().sizedness(ctx)
}
}
-impl HasTypeParamInArray for ItemId {
+impl<T> HasTypeParamInArray for T
+where
+ T: Copy + Into<ItemId>
+{
fn has_type_param_in_array(&self, ctx: &BindgenContext) -> bool {
debug_assert!(
ctx.in_codegen_phase(),
"You're not supposed to call this yet"
);
- ctx.lookup_item_id_has_type_param_in_array(self)
+ ctx.lookup_has_type_param_in_array(*self)
}
}
@@ -990,15 +1063,18 @@ impl HasTypeParamInArray for Item {
ctx.in_codegen_phase(),
"You're not supposed to call this yet"
);
- ctx.lookup_item_id_has_type_param_in_array(&self.id())
+ ctx.lookup_has_type_param_in_array(self.id())
}
}
-impl HasFloat for ItemId {
+impl<T> HasFloat for T
+where
+ T: Copy + Into<ItemId>
+{
fn has_float(&self, ctx: &BindgenContext) -> bool {
debug_assert!(ctx.in_codegen_phase(),
"You're not supposed to call this yet");
- ctx.lookup_item_id_has_float(self)
+ ctx.lookup_has_float(*self)
}
}
@@ -1006,7 +1082,7 @@ impl HasFloat for Item {
fn has_float(&self, ctx: &BindgenContext) -> bool {
debug_assert!(ctx.in_codegen_phase(),
"You're not supposed to call this yet");
- ctx.lookup_item_id_has_float(&self.id())
+ ctx.lookup_has_float(self.id())
}
}
@@ -1038,11 +1114,14 @@ impl DotAttributes for Item {
}
}
-impl TemplateParameters for ItemId {
+impl<T> TemplateParameters for T
+where
+ T: Copy + Into<ItemId>
+{
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
ctx.resolve_item_fallible(*self).and_then(|item| {
item.self_template_params(ctx)
})
@@ -1053,7 +1132,7 @@ impl TemplateParameters for Item {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
self.kind.self_template_params(ctx)
}
}
@@ -1062,7 +1141,7 @@ impl TemplateParameters for ItemKind {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
match *self {
ItemKind::Type(ref ty) => ty.self_template_params(ctx),
// If we start emitting bindings to explicitly instantiated
@@ -1082,7 +1161,7 @@ fn visit_child(
ty: &clang::Type,
parent_id: Option<ItemId>,
ctx: &mut BindgenContext,
- result: &mut Result<ItemId, ParseError>,
+ result: &mut Result<TypeId, ParseError>,
) -> clang_sys::CXChildVisitResult {
use clang_sys::*;
if result.is_ok() {
@@ -1106,7 +1185,7 @@ impl ClangItemParser for Item {
kind: TypeKind,
is_const: bool,
ctx: &mut BindgenContext,
- ) -> ItemId {
+ ) -> TypeId {
// Feel free to add more here, I'm just lazy.
match kind {
TypeKind::Void |
@@ -1118,13 +1197,13 @@ impl ClangItemParser for Item {
let ty = Type::new(None, None, kind, is_const);
let id = ctx.next_item_id();
- let module = ctx.root_module();
+ let module = ctx.root_module().into();
ctx.add_item(
Item::new(id, None, None, module, ItemKind::Type(ty)),
None,
None,
);
- id
+ id.as_type_id_unchecked()
}
@@ -1145,7 +1224,7 @@ impl ClangItemParser for Item {
let comment = cursor.raw_comment();
let annotations = Annotations::new(&cursor);
- let current_module = ctx.current_module();
+ let current_module = ctx.current_module().into();
let relevant_parent_id = parent_id.unwrap_or(current_module);
macro_rules! try_parse {
@@ -1198,10 +1277,11 @@ impl ClangItemParser for Item {
cursor,
parent_id,
ctx,
- ));
+ ).into());
}
- parent_id.or_else(|| ctx.known_semantic_parent(definition))
- .unwrap_or(ctx.current_module())
+ ctx.known_semantic_parent(definition)
+ .or(parent_id)
+ .unwrap_or(ctx.current_module().into())
}
None => relevant_parent_id,
};
@@ -1212,7 +1292,7 @@ impl ClangItemParser for Item {
Some(relevant_parent_id),
ctx,
) {
- Ok(ty) => return Ok(ty),
+ Ok(ty) => return Ok(ty.into()),
Err(ParseError::Recurse) => return Err(ParseError::Recurse),
Err(ParseError::Continue) => {}
}
@@ -1259,7 +1339,7 @@ impl ClangItemParser for Item {
location: clang::Cursor,
parent_id: Option<ItemId>,
ctx: &mut BindgenContext,
- ) -> ItemId {
+ ) -> TypeId {
let id = ctx.next_item_id();
Self::from_ty_or_ref_with_id(id, ty, location, parent_id, ctx)
}
@@ -1280,7 +1360,7 @@ impl ClangItemParser for Item {
location: clang::Cursor,
parent_id: Option<ItemId>,
ctx: &mut BindgenContext,
- ) -> ItemId {
+ ) -> TypeId {
debug!(
"from_ty_or_ref_with_id: {:?} {:?}, {:?}, {:?}",
potential_id,
@@ -1323,13 +1403,13 @@ impl ClangItemParser for Item {
potential_id,
None,
None,
- parent_id.unwrap_or(current_module),
+ parent_id.unwrap_or(current_module.into()),
ItemKind::Type(Type::new(None, None, kind, is_const)),
),
Some(clang::Cursor::null()),
None,
);
- potential_id
+ potential_id.as_type_id_unchecked()
}
fn from_ty(
@@ -1337,7 +1417,7 @@ impl ClangItemParser for Item {
location: clang::Cursor,
parent_id: Option<ItemId>,
ctx: &mut BindgenContext,
- ) -> Result<ItemId, ParseError> {
+ ) -> Result<TypeId, ParseError> {
let id = ctx.next_item_id();
Item::from_ty_with_id(id, ty, location, parent_id, ctx)
}
@@ -1356,7 +1436,7 @@ impl ClangItemParser for Item {
location: clang::Cursor,
parent_id: Option<ItemId>,
ctx: &mut BindgenContext,
- ) -> Result<ItemId, ParseError> {
+ ) -> Result<TypeId, ParseError> {
use clang_sys::*;
debug!(
@@ -1427,11 +1507,12 @@ impl ClangItemParser for Item {
)
{
debug!("Avoiding recursion parsing type: {:?}", ty);
- return Ok(partial.id());
+ // Unchecked because we haven't finished this type yet.
+ return Ok(partial.id().as_type_id_unchecked());
}
}
- let current_module = ctx.current_module();
+ let current_module = ctx.current_module().into();
let partial_ty = PartialType::new(declaration_to_look_for, id);
if valid_decl {
ctx.begin_parsing(partial_ty);
@@ -1440,7 +1521,7 @@ impl ClangItemParser for Item {
let result = Type::from_clang_ty(id, ty, location, parent_id, ctx);
let relevant_parent_id = parent_id.unwrap_or(current_module);
let ret = match result {
- Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty),
+ Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty.expect_type_id(ctx)),
Ok(ParseResult::New(item, declaration)) => {
ctx.add_item(
Item::new(
@@ -1453,7 +1534,7 @@ impl ClangItemParser for Item {
declaration,
Some(location),
);
- Ok(id)
+ Ok(id.as_type_id_unchecked())
}
Err(ParseError::Continue) => Err(ParseError::Continue),
Err(ParseError::Recurse) => {
@@ -1516,7 +1597,7 @@ impl ClangItemParser for Item {
with_id: Option<ItemId>,
location: clang::Cursor,
ctx: &mut BindgenContext,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
let ty = location.cur_type();
debug!(
@@ -1654,7 +1735,7 @@ impl ClangItemParser for Item {
// referenced with namespace prefixes, and they can't inherit anything
// from their parent either, so it is simplest to just hang them off
// something we know will always exist.
- let parent = ctx.root_module();
+ let parent = ctx.root_module().into();
if let Some(id) = ctx.get_type_param(&definition) {
if let Some(with_id) = with_id {
@@ -1679,7 +1760,7 @@ impl ClangItemParser for Item {
ItemKind::Type(Type::named(name)),
);
ctx.add_type_param(item, definition);
- Some(id)
+ Some(id.as_type_id_unchecked())
}
}
@@ -1740,7 +1821,7 @@ impl ItemCanonicalPath for Item {
let target = ctx.resolve_item(self.name_target(ctx));
let mut path: Vec<_> = target
.ancestors(ctx)
- .chain(iter::once(ctx.root_module()))
+ .chain(iter::once(ctx.root_module().into()))
.map(|id| ctx.resolve_item(id))
.filter(|item| {
item.id() == target.id() ||
diff --git a/src/ir/layout.rs b/src/ir/layout.rs
index 4b0b1769..ac875ca4 100644
--- a/src/ir/layout.rs
+++ b/src/ir/layout.rs
@@ -2,7 +2,7 @@
use super::derive::{CanTriviallyDeriveCopy, CanTriviallyDeriveDebug,
CanTriviallyDeriveDefault, CanTriviallyDeriveHash,
- CanTriviallyDerivePartialEq};
+ CanTriviallyDerivePartialEqOrPartialOrd, CanDerive, CannotDeriveReason};
use super::ty::{RUST_DERIVE_IN_ARRAY_LIMIT, Type, TypeKind};
use clang;
use std::{cmp, mem};
@@ -33,8 +33,8 @@ impl Layout {
/// packed.
pub fn new(size: usize, align: usize) -> Self {
Layout {
- size: size,
- align: align,
+ size,
+ align,
packed: false,
}
}
@@ -104,44 +104,49 @@ impl Opaque {
None
}
}
-}
-impl CanTriviallyDeriveDebug for Opaque {
- fn can_trivially_derive_debug(&self) -> bool {
+ /// Return `true` if this opaque layout's array size will fit within the
+ /// maximum number of array elements that Rust allows deriving traits
+ /// with. Return `false` otherwise.
+ pub fn array_size_within_derive_limit(&self) -> bool {
self.array_size().map_or(false, |size| {
size <= RUST_DERIVE_IN_ARRAY_LIMIT
})
}
}
+impl CanTriviallyDeriveDebug for Opaque {
+ fn can_trivially_derive_debug(&self) -> bool {
+ self.array_size_within_derive_limit()
+ }
+}
+
impl CanTriviallyDeriveDefault for Opaque {
fn can_trivially_derive_default(&self) -> bool {
- self.array_size().map_or(false, |size| {
- size <= RUST_DERIVE_IN_ARRAY_LIMIT
- })
+ self.array_size_within_derive_limit()
}
}
impl CanTriviallyDeriveCopy for Opaque {
fn can_trivially_derive_copy(&self) -> bool {
- self.array_size().map_or(false, |size| {
- size <= RUST_DERIVE_IN_ARRAY_LIMIT
- })
+ self.array_size_within_derive_limit()
}
}
impl CanTriviallyDeriveHash for Opaque {
fn can_trivially_derive_hash(&self) -> bool {
- self.array_size().map_or(false, |size| {
- size <= RUST_DERIVE_IN_ARRAY_LIMIT
- })
+ self.array_size_within_derive_limit()
}
}
-impl CanTriviallyDerivePartialEq for Opaque {
- fn can_trivially_derive_partialeq(&self) -> bool {
- self.array_size().map_or(false, |size| {
- size <= RUST_DERIVE_IN_ARRAY_LIMIT
+impl CanTriviallyDerivePartialEqOrPartialOrd for Opaque {
+ fn can_trivially_derive_partialeq_or_partialord(&self) -> CanDerive {
+ self.array_size().map_or(CanDerive::No(CannotDeriveReason::Other), |size| {
+ if size <= RUST_DERIVE_IN_ARRAY_LIMIT {
+ CanDerive::Yes
+ } else {
+ CanDerive::No(CannotDeriveReason::ArrayTooLarge)
+ }
})
}
}
diff --git a/src/ir/module.rs b/src/ir/module.rs
index c66623dd..af46d4ac 100644
--- a/src/ir/module.rs
+++ b/src/ir/module.rs
@@ -83,11 +83,11 @@ impl ClangSubItemParser for Module {
let module_id = ctx.module(cursor);
ctx.with_module(module_id, |ctx| {
cursor.visit(
- |cursor| parse_one(ctx, cursor, Some(module_id)),
+ |cursor| parse_one(ctx, cursor, Some(module_id.into())),
)
});
- Ok(ParseResult::AlreadyResolved(module_id))
+ Ok(ParseResult::AlreadyResolved(module_id.into()))
}
_ => Err(ParseError::Continue),
}
diff --git a/src/ir/objc.rs b/src/ir/objc.rs
index cabbd389..0f72c399 100644
--- a/src/ir/objc.rs
+++ b/src/ir/objc.rs
@@ -236,13 +236,21 @@ impl ObjCMethod {
);
}
+ // Get arguments without type signatures to pass to `msg_send!`
+ let mut args_without_types = vec![];
+ for arg in args.iter() {
+ let name_and_sig: Vec<&str> = arg.as_str().split(' ').collect();
+ let name = name_and_sig[0];
+ args_without_types.push(quote::Ident::new(name))
+ };
+
let args = split_name
.into_iter()
- .zip(args.iter())
- .map(|(arg, ty)| quote! { #arg : #ty });
+ .zip(args_without_types)
+ .map(|(arg, arg_val)| quote! { #arg : #arg_val });
quote! {
- #( #args ),*
+ #( #args )*
}
}
}
diff --git a/src/ir/template.rs b/src/ir/template.rs
index c1650abc..11a799f4 100644
--- a/src/ir/template.rs
+++ b/src/ir/template.rs
@@ -27,7 +27,7 @@
//! };
//! ```
-use super::context::{BindgenContext, ItemId};
+use super::context::{BindgenContext, ItemId, TypeId};
use super::item::{IsOpaque, Item, ItemAncestors, ItemCanonicalPath};
use super::traversal::{EdgeKind, Trace, Tracer};
use clang;
@@ -109,7 +109,7 @@ pub trait TemplateParameters {
/// anything but types, so we must treat them as opaque, and avoid
/// instantiating them.
fn self_template_params(&self, ctx: &BindgenContext)
- -> Option<Vec<ItemId>>;
+ -> Option<Vec<TypeId>>;
/// Get the number of free template parameters this template declaration
/// has.
@@ -136,7 +136,7 @@ pub trait TemplateParameters {
/// how we would fully reference such a member type in C++:
/// `Foo<int,char>::Inner`. `Foo` *must* be instantiated with template
/// arguments before we can gain access to the `Inner` member type.
- fn all_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>>
+ fn all_template_params(&self, ctx: &BindgenContext) -> Option<Vec<TypeId>>
where
Self: ItemAncestors,
{
@@ -159,7 +159,7 @@ pub trait TemplateParameters {
/// Get only the set of template parameters that this item uses. This is a
/// subset of `all_template_params` and does not necessarily contain any of
/// `self_template_params`.
- fn used_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>>
+ fn used_template_params(&self, ctx: &BindgenContext) -> Option<Vec<TypeId>>
where
Self: AsRef<ItemId>,
{
@@ -190,7 +190,7 @@ pub trait AsTemplateParam {
&self,
ctx: &BindgenContext,
extra: &Self::Extra,
- ) -> Option<ItemId>;
+ ) -> Option<TypeId>;
/// Is this a named template type parameter?
fn is_template_param(
@@ -206,34 +206,31 @@ pub trait AsTemplateParam {
#[derive(Clone, Debug)]
pub struct TemplateInstantiation {
/// The template definition which this is instantiating.
- definition: ItemId,
+ definition: TypeId,
/// The concrete template arguments, which will be substituted in the
/// definition for the generic template parameters.
- args: Vec<ItemId>,
+ args: Vec<TypeId>,
}
impl TemplateInstantiation {
/// Construct a new template instantiation from the given parts.
- pub fn new<I>(
- template_definition: ItemId,
- template_args: I,
- ) -> TemplateInstantiation
+ pub fn new<I>(definition: TypeId, args: I) -> TemplateInstantiation
where
- I: IntoIterator<Item = ItemId>,
+ I: IntoIterator<Item = TypeId>,
{
TemplateInstantiation {
- definition: template_definition,
- args: template_args.into_iter().collect(),
+ definition,
+ args: args.into_iter().collect(),
}
}
/// Get the template definition for this instantiation.
- pub fn template_definition(&self) -> ItemId {
+ pub fn template_definition(&self) -> TypeId {
self.definition
}
/// Get the concrete template arguments used in this instantiation.
- pub fn template_arguments(&self) -> &[ItemId] {
+ pub fn template_arguments(&self) -> &[TypeId] {
&self.args[..]
}
@@ -353,9 +350,9 @@ impl Trace for TemplateInstantiation {
where
T: Tracer,
{
- tracer.visit_kind(self.definition, EdgeKind::TemplateDeclaration);
- for &item in self.template_arguments() {
- tracer.visit_kind(item, EdgeKind::TemplateArgument);
+ tracer.visit_kind(self.definition.into(), EdgeKind::TemplateDeclaration);
+ for arg in self.template_arguments() {
+ tracer.visit_kind(arg.into(), EdgeKind::TemplateArgument);
}
}
}
diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs
index f55acc10..b9b3179a 100644
--- a/src/ir/traversal.rs
+++ b/src/ir/traversal.rs
@@ -21,8 +21,8 @@ impl Edge {
/// Construct a new edge whose referent is `to` and is of the given `kind`.
pub fn new(to: ItemId, kind: EdgeKind) -> Edge {
Edge {
- to: to,
- kind: kind,
+ to,
+ kind,
}
}
}
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 8cfbde10..bfb4c48e 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -1,7 +1,7 @@
//! Everything related to types in our intermediate representation.
use super::comp::CompInfo;
-use super::context::{BindgenContext, ItemId};
+use super::context::{BindgenContext, ItemId, TypeId};
use super::dot::DotAttributes;
use super::enum_ty::Enum;
use super::function::FunctionSig;
@@ -69,10 +69,10 @@ impl Type {
is_const: bool,
) -> Self {
Type {
- name: name,
- layout: layout,
- kind: kind,
- is_const: is_const,
+ name,
+ layout,
+ kind,
+ is_const,
}
}
@@ -194,6 +194,15 @@ impl Type {
}
}
+ /// Cast this type to an integer kind, or `None` if it is not an integer
+ /// type.
+ pub fn as_integer(&self) -> Option<IntKind> {
+ match self.kind {
+ TypeKind::Int(int_kind) => Some(int_kind),
+ _ => None,
+ }
+ }
+
/// Is this a `const` qualified type?
pub fn is_const(&self) -> bool {
self.is_const
@@ -212,7 +221,7 @@ impl Type {
pub fn is_incomplete_array(&self, ctx: &BindgenContext) -> Option<ItemId> {
match self.kind {
TypeKind::Array(item, len) => {
- if len == 0 { Some(item) } else { None }
+ if len == 0 { Some(item.into()) } else { None }
}
TypeKind::ResolvedTypeRef(inner) => {
ctx.resolve_type(inner).is_incomplete_array(ctx)
@@ -275,8 +284,8 @@ impl Type {
ctx: &BindgenContext,
) -> Option<Cow<'a, str>> {
let name_info = match *self.kind() {
- TypeKind::Pointer(inner) => Some((inner, Cow::Borrowed("ptr"))),
- TypeKind::Reference(inner) => Some((inner, Cow::Borrowed("ref"))),
+ TypeKind::Pointer(inner) => Some((inner.into(), Cow::Borrowed("ptr"))),
+ TypeKind::Reference(inner) => Some((inner.into(), Cow::Borrowed("ref"))),
TypeKind::Array(inner, length) => {
Some((inner, format!("array{}", length).into()))
}
@@ -383,7 +392,7 @@ impl AsTemplateParam for Type {
&self,
ctx: &BindgenContext,
item: &Item,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
self.kind.as_template_param(ctx, item)
}
}
@@ -395,9 +404,9 @@ impl AsTemplateParam for TypeKind {
&self,
ctx: &BindgenContext,
item: &Item,
- ) -> Option<ItemId> {
+ ) -> Option<TypeId> {
match *self {
- TypeKind::TypeParam => Some(item.id()),
+ TypeKind::TypeParam => Some(item.id().expect_type_id(ctx)),
TypeKind::ResolvedTypeRef(id) => id.as_template_param(ctx, &()),
_ => None,
}
@@ -534,7 +543,7 @@ impl TemplateParameters for Type {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
self.kind.self_template_params(ctx)
}
}
@@ -543,7 +552,7 @@ impl TemplateParameters for TypeKind {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<ItemId>> {
+ ) -> Option<Vec<TypeId>> {
match *self {
TypeKind::ResolvedTypeRef(id) => {
ctx.resolve_type(id).self_template_params(ctx)
@@ -626,14 +635,14 @@ pub enum TypeKind {
Complex(FloatKind),
/// A type alias, with a name, that points to another type.
- Alias(ItemId),
+ Alias(TypeId),
/// A templated alias, pointing to an inner type, just as `Alias`, but with
/// template parameters.
- TemplateAlias(ItemId, Vec<ItemId>),
+ TemplateAlias(TypeId, Vec<TypeId>),
- /// An array of a type and a lenght.
- Array(ItemId, usize),
+ /// An array of a type and a length.
+ Array(TypeId, usize),
/// A function type, with a given signature.
Function(FunctionSig),
@@ -643,13 +652,13 @@ pub enum TypeKind {
/// A pointer to a type. The bool field represents whether it's const or
/// not.
- Pointer(ItemId),
+ Pointer(TypeId),
/// A pointer to an Apple block.
BlockPointer,
/// A reference to a type, as in: int& foo().
- Reference(ItemId),
+ Reference(TypeId),
/// An instantiation of an abstract template definition with a set of
/// concrete template arguments.
@@ -673,7 +682,7 @@ pub enum TypeKind {
///
/// These are generated after we resolve a forward declaration, or when we
/// replace one type with another.
- ResolvedTypeRef(ItemId),
+ ResolvedTypeRef(TypeId),
/// A named type, that is, a template parameter.
TypeParam,
@@ -689,50 +698,6 @@ pub enum TypeKind {
}
impl Type {
- /// Whether this type is unsized, that is, has no members. This is used to
- /// derive whether we should generate a dummy `_address` field for structs,
- /// to comply to the C and C++ layouts, that specify that every type needs
- /// to be addressable.
- pub fn is_unsized(&self, ctx: &BindgenContext, itemid: &ItemId) -> bool {
- debug_assert!(ctx.in_codegen_phase(), "Not yet");
-
- match self.kind {
- TypeKind::Void => true,
- TypeKind::Comp(ref ci) => ci.is_unsized(ctx, itemid),
- TypeKind::Opaque => self.layout.map_or(true, |l| l.size == 0),
- TypeKind::Array(inner, size) => {
- size == 0 || ctx.resolve_type(inner).is_unsized(ctx, &inner)
- }
- TypeKind::ResolvedTypeRef(inner) |
- TypeKind::Alias(inner) |
- TypeKind::TemplateAlias(inner, _) => {
- ctx.resolve_type(inner).is_unsized(ctx, &inner)
- }
- TypeKind::TemplateInstantiation(ref inst) => {
- let definition = inst.template_definition();
- ctx.resolve_type(definition).is_unsized(ctx, &definition)
- }
- TypeKind::TypeParam |
- TypeKind::Int(..) |
- TypeKind::Float(..) |
- TypeKind::Complex(..) |
- TypeKind::Function(..) |
- TypeKind::Enum(..) |
- TypeKind::Reference(..) |
- TypeKind::NullPtr |
- TypeKind::BlockPointer |
- TypeKind::ObjCId |
- TypeKind::ObjCSel |
- TypeKind::Pointer(..) => false,
-
- TypeKind::ObjCInterface(..) => true, // dunno?
-
- TypeKind::UnresolvedTypeRef(..) => {
- unreachable!("Should have been resolved after parsing!");
- }
- }
- }
-
/// This is another of the nasty methods. This one is the one that takes
/// care of the core logic of converting a clang type to a `Type`.
///
@@ -755,7 +720,7 @@ impl Type {
);
if let Some(ty) = already_resolved {
debug!("{:?} already resolved: {:?}", ty, location);
- return Ok(ParseResult::AlreadyResolved(ty));
+ return Ok(ParseResult::AlreadyResolved(ty.into()));
}
}
@@ -1035,14 +1000,14 @@ impl Type {
referenced_ty
);
- let item = Item::from_ty_or_ref_with_id(
+ let id = Item::from_ty_or_ref_with_id(
potential_id,
referenced_ty,
declaration,
parent_id,
ctx,
);
- return Ok(ParseResult::AlreadyResolved(item));
+ return Ok(ParseResult::AlreadyResolved(id.into()));
}
CXCursor_NamespaceRef => {
return Err(ParseError::Continue);
@@ -1261,13 +1226,13 @@ impl Trace for Type {
TypeKind::Array(inner, _) |
TypeKind::Alias(inner) |
TypeKind::ResolvedTypeRef(inner) => {
- tracer.visit_kind(inner, EdgeKind::TypeReference);
+ tracer.visit_kind(inner.into(), EdgeKind::TypeReference);
}
TypeKind::TemplateAlias(inner, ref template_params) => {
- tracer.visit_kind(inner, EdgeKind::TypeReference);
- for &item in template_params {
+ tracer.visit_kind(inner.into(), EdgeKind::TypeReference);
+ for param in template_params {
tracer.visit_kind(
- item,
+ param.into(),
EdgeKind::TemplateParameterDefinition,
);
}
@@ -1279,7 +1244,7 @@ impl Trace for Type {
TypeKind::Function(ref sig) => sig.trace(context, tracer, &()),
TypeKind::Enum(ref en) => {
if let Some(repr) = en.repr() {
- tracer.visit(repr);
+ tracer.visit(repr.into());
}
}
TypeKind::UnresolvedTypeRef(_, _, Some(id)) => {
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 987bfd50..9d6c1452 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -1,6 +1,6 @@
//! Intermediate representation of variables.
-use super::context::{BindgenContext, ItemId};
+use super::context::{BindgenContext, TypeId};
use super::dot::DotAttributes;
use super::function::cursor_mangling;
use super::int::IntKind;
@@ -35,7 +35,7 @@ pub struct Var {
/// The mangled name of the variable.
mangled_name: Option<String>,
/// The type of the variable.
- ty: ItemId,
+ ty: TypeId,
/// The value of the variable, that needs to be suitable for `ty`.
val: Option<VarType>,
/// Whether this variable is const.
@@ -46,18 +46,18 @@ impl Var {
/// Construct a new `Var`.
pub fn new(
name: String,
- mangled: Option<String>,
- ty: ItemId,
+ mangled_name: Option<String>,
+ ty: TypeId,
val: Option<VarType>,
is_const: bool,
) -> Var {
assert!(!name.is_empty());
Var {
- name: name,
- mangled_name: mangled,
- ty: ty,
- val: val,
- is_const: is_const,
+ name,
+ mangled_name,
+ ty,
+ val,
+ is_const,
}
}
@@ -72,7 +72,7 @@ impl Var {
}
/// Get this variable's type.
- pub fn ty(&self) -> ItemId {
+ pub fn ty(&self) -> TypeId {
self.ty
}
diff --git a/src/lib.rs b/src/lib.rs
index 757a8a7a..fccee7b9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,9 +7,6 @@
#![deny(missing_docs)]
#![deny(warnings)]
#![deny(unused_extern_crates)]
-// We internally use the deprecated BindgenOptions all over the place. Once we
-// remove its `pub` declaration, we can un-deprecate it and remove this pragma.
-#![allow(deprecated)]
// To avoid rather annoying warnings when matching with CXCursor_xxx as a
// constant.
#![allow(non_upper_case_globals)]
@@ -242,6 +239,14 @@ impl Builder {
output_vector.push("--no-layout-tests".into());
}
+ if self.options.impl_debug {
+ output_vector.push("--impl-debug".into());
+ }
+
+ if self.options.impl_partialeq {
+ output_vector.push("--impl-partialeq".into());
+ }
+
if !self.options.derive_copy {
output_vector.push("--no-derive-copy".into());
}
@@ -250,10 +255,6 @@ impl Builder {
output_vector.push("--no-derive-debug".into());
}
- if !self.options.impl_debug {
- output_vector.push("--impl-debug".into());
- }
-
if !self.options.derive_default {
output_vector.push("--no-derive-default".into());
} else {
@@ -264,6 +265,14 @@ impl Builder {
output_vector.push("--with-derive-hash".into());
}
+ if self.options.derive_partialord {
+ output_vector.push("--with-derive-partialord".into());
+ }
+
+ if self.options.derive_ord {
+ output_vector.push("--with-derive-ord".into());
+ }
+
if self.options.derive_partialeq {
output_vector.push("--with-derive-partialeq".into());
}
@@ -487,7 +496,7 @@ impl Builder {
}
if !self.options.rustfmt_bindings {
- output_vector.push("--rustfmt-bindings".into());
+ output_vector.push("--no-rustfmt-bindings".into());
}
if let Some(path) = self.options
@@ -499,6 +508,48 @@ impl Builder {
output_vector.push(path.into());
}
+ self.options
+ .no_partialeq_types
+ .get_items()
+ .iter()
+ .map(|item| {
+ output_vector.push("--no-partialeq".into());
+ output_vector.push(
+ item.trim_left_matches("^")
+ .trim_right_matches("$")
+ .into(),
+ );
+ })
+ .count();
+
+ self.options
+ .no_copy_types
+ .get_items()
+ .iter()
+ .map(|item| {
+ output_vector.push("--no-copy".into());
+ output_vector.push(
+ item.trim_left_matches("^")
+ .trim_right_matches("$")
+ .into(),
+ );
+ })
+ .count();
+
+ self.options
+ .no_hash_types
+ .get_items()
+ .iter()
+ .map(|item| {
+ output_vector.push("--no-hash".into());
+ output_vector.push(
+ item.trim_left_matches("^")
+ .trim_right_matches("$")
+ .into(),
+ );
+ })
+ .count();
+
output_vector
}
@@ -642,7 +693,15 @@ impl Builder {
/// Whitelist the given type so that it (and all types that it transitively
/// refers to) appears in the generated bindings. Regular expressions are
/// supported.
- pub fn whitelisted_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
+ #[deprecated = "use whitelist_type instead"]
+ pub fn whitelisted_type<T: AsRef<str>>(self, arg: T) -> Builder {
+ self.whitelist_type(arg)
+ }
+
+ /// Whitelist the given type so that it (and all types that it transitively
+ /// refers to) appears in the generated bindings. Regular expressions are
+ /// supported.
+ pub fn whitelist_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.whitelisted_types.insert(arg);
self
}
@@ -779,6 +838,18 @@ impl Builder {
self
}
+ /// Set whether `Debug` should be implemented, if it can not be derived automatically.
+ pub fn impl_debug(mut self, doit: bool) -> Self {
+ self.options.impl_debug = doit;
+ self
+ }
+
+ /// Set whether `PartialEq` should be implemented, if it can not be derived automatically.
+ pub fn impl_partialeq(mut self, doit: bool) -> Self {
+ self.options.impl_partialeq = doit;
+ self
+ }
+
/// Set whether `Copy` should be derived by default.
pub fn derive_copy(mut self, doit: bool) -> Self {
self.options.derive_copy = doit;
@@ -791,12 +862,6 @@ impl Builder {
self
}
- /// Set whether `Debug` should be implemented, if it can not be derived automatically.
- pub fn impl_debug(mut self, doit: bool) -> Self {
- self.options.impl_debug = doit;
- self
- }
-
/// Set whether `Default` should be derived by default.
pub fn derive_default(mut self, doit: bool) -> Self {
self.options.derive_default = doit;
@@ -809,9 +874,30 @@ impl Builder {
self
}
+ /// Set whether `PartialOrd` should be derived by default.
+ /// If we don't compute partialord, we also cannot compute
+ /// ord. Set the derive_ord to `false` when doit is `false`.
+ pub fn derive_partialord(mut self, doit: bool) -> Self {
+ self.options.derive_partialord = doit;
+ if !doit {
+ self.options.derive_ord = false;
+ }
+ self
+ }
+
+ /// Set whether `Ord` should be derived by default.
+ /// We can't compute `Ord` without computing `PartialOrd`,
+ /// so we set the same option to derive_partialord.
+ pub fn derive_ord(mut self, doit: bool) -> Self {
+ self.options.derive_ord = doit;
+ self.options.derive_partialord = doit;
+ self
+ }
+
/// Set whether `PartialEq` should be derived by default.
- /// If we don't compute partialeq, we also cannot compute
- /// eq. Set the derive_eq to `false` when doit is `false`.
+ ///
+ /// If we don't derive `PartialEq`, we also cannot derive `Eq`, so deriving
+ /// `Eq` is also disabled when `doit` is `false`.
pub fn derive_partialeq(mut self, doit: bool) -> Self {
self.options.derive_partialeq = doit;
if !doit {
@@ -821,16 +907,19 @@ impl Builder {
}
/// Set whether `Eq` should be derived by default.
- /// We can't compute Eq without computing PartialEq, so
- /// we set the same option to derive_partialeq.
+ ///
+ /// We can't derive `Eq` without also deriving `PartialEq`, so we also
+ /// enable deriving `PartialEq` when `doit` is `true`.
pub fn derive_eq(mut self, doit: bool) -> Self {
self.options.derive_eq = doit;
- self.options.derive_partialeq = doit;
+ if doit {
+ self.options.derive_partialeq = doit;
+ }
self
}
- /// Set whether or not to time bindgen phases, and print
- /// information to stderr.
+ /// Set whether or not to time bindgen phases, and print information to
+ /// stderr.
pub fn time_phases(mut self, doit: bool) -> Self {
self.options.time_phases = doit;
self
@@ -1090,21 +1179,39 @@ impl Builder {
))
}
}
+
+ /// Don't derive `PartialEq` for a given type. Regular
+ /// expressions are supported.
+ pub fn no_partialeq(mut self, arg: String) -> Builder {
+ self.options.no_partialeq_types.insert(arg);
+ self
+ }
+
+ /// Don't derive `Copy` for a given type. Regular
+ /// expressions are supported.
+ pub fn no_copy(mut self, arg: String) -> Self {
+ self.options.no_copy_types.insert(arg);
+ self
+ }
+
+ /// Don't derive `Hash` for a given type. Regular
+ /// expressions are supported.
+ pub fn no_hash(mut self, arg: String) -> Builder {
+ self.options.no_hash_types.insert(arg);
+ self
+ }
}
/// Configuration options for generated bindings.
-///
-/// Deprecated: use a `Builder` instead.
#[derive(Debug)]
-#[deprecated]
-pub struct BindgenOptions {
+struct BindgenOptions {
/// The set of types that have been blacklisted and should not appear
/// anywhere in the generated code.
- pub blacklisted_types: RegexSet,
+ blacklisted_types: RegexSet,
/// The set of types that should be treated as opaque structures in the
/// generated code.
- pub opaque_types: RegexSet,
+ opaque_types: RegexSet,
/// The set of types that we should have bindings for in the generated
/// code.
@@ -1112,133 +1219,145 @@ pub struct BindgenOptions {
/// This includes all types transitively reachable from any type in this
/// set. One might think of whitelisted types/vars/functions as GC roots,
/// and the generated Rust code as including everything that gets marked.
- pub whitelisted_types: RegexSet,
+ whitelisted_types: RegexSet,
/// Whitelisted functions. See docs for `whitelisted_types` for more.
- pub whitelisted_functions: RegexSet,
+ whitelisted_functions: RegexSet,
/// Whitelisted variables. See docs for `whitelisted_types` for more.
- pub whitelisted_vars: RegexSet,
+ whitelisted_vars: RegexSet,
/// The enum patterns to mark an enum as bitfield.
- pub bitfield_enums: RegexSet,
+ bitfield_enums: RegexSet,
/// The enum patterns to mark an enum as a Rust enum.
- pub rustified_enums: RegexSet,
+ rustified_enums: RegexSet,
/// The enum patterns to mark an enum as a module of constants.
- pub constified_enum_modules: RegexSet,
+ constified_enum_modules: RegexSet,
/// Whether we should generate builtins or not.
- pub builtins: bool,
+ builtins: bool,
/// The set of libraries we should link in the generated Rust code.
- pub links: Vec<(String, LinkType)>,
+ links: Vec<(String, LinkType)>,
/// True if we should dump the Clang AST for debugging purposes.
- pub emit_ast: bool,
+ emit_ast: bool,
/// True if we should dump our internal IR for debugging purposes.
- pub emit_ir: bool,
+ emit_ir: bool,
/// Output graphviz dot file.
- pub emit_ir_graphviz: Option<String>,
+ emit_ir_graphviz: Option<String>,
/// True if we should emulate C++ namespaces with Rust modules in the
/// generated bindings.
- pub enable_cxx_namespaces: bool,
+ enable_cxx_namespaces: bool,
/// True if we should avoid mangling names with namespaces.
- pub disable_name_namespacing: bool,
+ disable_name_namespacing: bool,
/// True if we should generate layout tests for generated structures.
- pub layout_tests: bool,
+ layout_tests: bool,
+
+ /// True if we should implement the Debug trait for C/C++ structures and types
+ /// that do not support automatically deriving Debug.
+ impl_debug: bool,
+
+ /// True if we should implement the PartialEq trait for C/C++ structures and types
+ /// that do not support autoamically deriving PartialEq.
+ impl_partialeq: bool,
/// True if we should derive Copy trait implementations for C/C++ structures
/// and types.
- pub derive_copy: bool,
+ derive_copy: bool,
/// True if we should derive Debug trait implementations for C/C++ structures
/// and types.
- pub derive_debug: bool,
-
- /// True if we should implement the Debug trait for C/C++ structures and types
- /// that do not support automatically deriving Debug.
- pub impl_debug: bool,
+ derive_debug: bool,
/// True if we should derive Default trait implementations for C/C++ structures
/// and types.
- pub derive_default: bool,
+ derive_default: bool,
/// True if we should derive Hash trait implementations for C/C++ structures
/// and types.
- pub derive_hash: bool,
+ derive_hash: bool,
+
+ /// True if we should derive PartialOrd trait implementations for C/C++ structures
+ /// and types.
+ derive_partialord: bool,
+
+ /// True if we should derive Ord trait implementations for C/C++ structures
+ /// and types.
+ derive_ord: bool,
/// True if we should derive PartialEq trait implementations for C/C++ structures
/// and types.
- pub derive_partialeq: bool,
+ derive_partialeq: bool,
/// True if we should derive Eq trait implementations for C/C++ structures
/// and types.
- pub derive_eq: bool,
+ derive_eq: bool,
/// True if we should avoid using libstd to use libcore instead.
- pub use_core: bool,
+ use_core: bool,
/// An optional prefix for the "raw" types, like `c_int`, `c_void`...
- pub ctypes_prefix: Option<String>,
+ ctypes_prefix: Option<String>,
/// Whether to time the bindgen phases.
- pub time_phases: bool,
+ time_phases: bool,
/// True if we should generate constant names that are **directly** under
/// namespaces.
- pub namespaced_constants: bool,
+ namespaced_constants: bool,
/// True if we should use MSVC name mangling rules.
- pub msvc_mangling: bool,
+ msvc_mangling: bool,
/// Whether we should convert float types to f32/f64 types.
- pub convert_floats: bool,
+ convert_floats: bool,
/// The set of raw lines to prepend to the generated Rust code.
- pub raw_lines: Vec<String>,
+ raw_lines: Vec<String>,
/// The set of arguments to pass straight through to Clang.
- pub clang_args: Vec<String>,
+ clang_args: Vec<String>,
/// The input header file.
- pub input_header: Option<String>,
+ input_header: Option<String>,
/// Unsaved files for input.
- pub input_unsaved_files: Vec<clang::UnsavedFile>,
+ input_unsaved_files: Vec<clang::UnsavedFile>,
/// A user-provided visitor to allow customizing different kinds of
/// situations.
- pub parse_callbacks: Option<Box<callbacks::ParseCallbacks>>,
+ parse_callbacks: Option<Box<callbacks::ParseCallbacks>>,
/// Which kind of items should we generate? By default, we'll generate all
/// of them.
- pub codegen_config: CodegenConfig,
+ codegen_config: CodegenConfig,
/// Whether to treat inline namespaces conservatively.
///
/// See the builder method description for more details.
- pub conservative_inline_namespaces: bool,
+ conservative_inline_namespaces: bool,
/// Wether to keep documentation comments in the generated output. See the
/// documentation for more details.
- pub generate_comments: bool,
+ generate_comments: bool,
/// Whether to generate inline functions. Defaults to false.
- pub generate_inline_functions: bool,
+ generate_inline_functions: bool,
/// Wether to whitelist types recursively. Defaults to true.
- pub whitelist_recursively: bool,
+ whitelist_recursively: bool,
/// Intead of emitting 'use objc;' to files generated from objective c files,
/// generate '#[macro_use] extern crate objc;'
- pub objc_extern_crate: bool,
+ objc_extern_crate: bool,
/// Whether to use the clang-provided name mangling. This is true and
/// probably needed for C++ features.
@@ -1247,10 +1366,10 @@ pub struct BindgenOptions {
/// some cases for non-mangled functions, see [1], so we allow disabling it.
///
/// [1]: https://github.com/rust-lang-nursery/rust-bindgen/issues/528
- pub enable_mangling: bool,
+ enable_mangling: bool,
/// Whether to prepend the enum name to bitfield or constant variants.
- pub prepend_enum_name: bool,
+ prepend_enum_name: bool,
/// Version of the Rust compiler to target
rust_target: RustTarget,
@@ -1259,11 +1378,21 @@ pub struct BindgenOptions {
rust_features: RustFeatures,
/// Whether rustfmt should format the generated bindings.
- pub rustfmt_bindings: bool,
+ rustfmt_bindings: bool,
/// The absolute path to the rustfmt configuration file, if None, the standard rustfmt
/// options are used.
- pub rustfmt_configuration_file: Option<PathBuf>,
+
+ rustfmt_configuration_file: Option<PathBuf>,
+
+ /// The set of types that we should not derive `PartialEq` for.
+ no_partialeq_types: RegexSet,
+
+ /// The set of types that we should not derive `Copy` for.
+ no_copy_types: RegexSet,
+
+ /// The set of types that we should not derive `Hash` for.
+ no_hash_types: RegexSet,
}
/// TODO(emilio): This is sort of a lie (see the error message that results from
@@ -1281,6 +1410,9 @@ impl BindgenOptions {
self.bitfield_enums.build();
self.constified_enum_modules.build();
self.rustified_enums.build();
+ self.no_partialeq_types.build();
+ self.no_copy_types.build();
+ self.no_hash_types.build();
}
/// Update rust target version
@@ -1291,11 +1423,6 @@ impl BindgenOptions {
self.rust_features = rust_target.into();
}
- /// Get target Rust version
- pub fn rust_target(&self) -> RustTarget {
- self.rust_target
- }
-
/// Get features supported by target Rust version
pub fn rust_features(&self) -> RustFeatures {
self.rust_features
@@ -1323,11 +1450,14 @@ impl Default for BindgenOptions {
emit_ir: false,
emit_ir_graphviz: None,
layout_tests: true,
+ impl_debug: false,
+ impl_partialeq: false,
derive_copy: true,
derive_debug: true,
- impl_debug: false,
derive_default: false,
derive_hash: false,
+ derive_partialord: false,
+ derive_ord: false,
derive_partialeq: false,
derive_eq: false,
enable_cxx_namespaces: false,
@@ -1351,8 +1481,11 @@ impl Default for BindgenOptions {
enable_mangling: true,
prepend_enum_name: true,
time_phases: false,
- rustfmt_bindings: false,
+ rustfmt_bindings: true,
rustfmt_configuration_file: None,
+ no_partialeq_types: Default::default(),
+ no_copy_types: Default::default(),
+ no_hash_types: Default::default(),
}
}
}
@@ -1394,16 +1527,13 @@ fn ensure_libclang_is_loaded() {
/// Generated Rust bindings.
#[derive(Debug)]
pub struct Bindings {
- context: BindgenContext,
+ options: BindgenOptions,
module: quote::Tokens,
}
impl Bindings {
/// Generate bindings for the given options.
- ///
- /// Deprecated - use a `Builder` instead
- #[deprecated]
- pub fn generate(
+ pub(crate) fn generate(
mut options: BindgenOptions,
) -> Result<Bindings, ()> {
ensure_libclang_is_loaded();
@@ -1464,7 +1594,27 @@ impl Bindings {
}
}
+ #[cfg(unix)]
+ fn can_read(perms: &std::fs::Permissions) -> bool {
+ use std::os::unix::fs::PermissionsExt;
+ perms.mode() & 0o444 > 0
+ }
+
+ #[cfg(not(unix))]
+ fn can_read(_: &std::fs::Permissions) -> bool {
+ true
+ }
+
if let Some(h) = options.input_header.as_ref() {
+ let md = std::fs::metadata(h).ok().unwrap();
+ if !md.is_file() {
+ eprintln!("error: '{}' is a folder", h);
+ return Err(());
+ }
+ if !can_read(&md.permissions()) {
+ eprintln!("error: insufficient permissions to read '{}'", h);
+ return Err(());
+ }
options.clang_args.push(h.clone())
}
@@ -1481,10 +1631,10 @@ impl Bindings {
try!(parse(&mut context));
}
- let items = codegen::codegen(&mut context);
+ let (items, options) = codegen::codegen(context);
Ok(Bindings {
- context: context,
+ options: options,
module: quote! {
#( #items )*
}
@@ -1502,18 +1652,13 @@ impl Bindings {
/// Write these bindings as source text to a file.
pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
- {
- let file = try!(
- OpenOptions::new()
- .write(true)
- .truncate(true)
- .create(true)
- .open(path.as_ref())
- );
- self.write(Box::new(file))?;
- }
-
- self.rustfmt_generated_file(path.as_ref())
+ let file = OpenOptions::new()
+ .write(true)
+ .truncate(true)
+ .create(true)
+ .open(path.as_ref())?;
+ self.write(Box::new(file))?;
+ Ok(())
}
/// Write these bindings as source text to the given `Write`able.
@@ -1522,39 +1667,58 @@ impl Bindings {
"/* automatically generated by rust-bindgen */\n\n".as_bytes(),
)?;
- for line in self.context.options().raw_lines.iter() {
+ for line in self.options.raw_lines.iter() {
writer.write(line.as_bytes())?;
writer.write("\n".as_bytes())?;
}
- if !self.context.options().raw_lines.is_empty() {
+
+ if !self.options.raw_lines.is_empty() {
writer.write("\n".as_bytes())?;
}
- writer.write(self.module.as_str().as_bytes())?;
+ let bindings = self.module.as_str().to_string();
+
+ match self.rustfmt_generated_string(bindings) {
+ Ok(rustfmt_bindings) => {
+ writer.write(rustfmt_bindings.as_str().as_bytes())?;
+ },
+ Err(err) => eprintln!("{:?}", err),
+ }
Ok(())
}
- /// Checks if rustfmt_bindings is set and runs rustfmt on the file
- fn rustfmt_generated_file(&self, file: &Path) -> io::Result<()> {
- let _t = self.context.timer("rustfmt_generated_file");
+ /// Checks if rustfmt_bindings is set and runs rustfmt on the string
+ fn rustfmt_generated_string(&self, source: String) -> io::Result<String> {
+ let _t = time::Timer::new("rustfmt_generated_string")
+ .with_output(self.options.time_phases);
- if !self.context.options().rustfmt_bindings {
- return Ok(());
+ if !self.options.rustfmt_bindings {
+ return Ok(source);
}
let rustfmt = if let Ok(rustfmt) = which::which("rustfmt") {
rustfmt
} else {
- return Err(io::Error::new(
- io::ErrorKind::Other,
- "Rustfmt activated, but it could not be found in global path.",
- ));
+ eprintln!("warning: could not find usable rustfmt to pretty print bindings");
+ return Ok(source);
};
- let mut cmd = Command::new(rustfmt);
+ // Prefer using the `rustfmt-nightly` version of `rustmft`, if
+ // possible. It requires being run via `rustup run nightly ...`.
+ let mut cmd = if let Ok(rustup) = which::which("rustup") {
+ let mut cmd = Command::new(rustup);
+ cmd.args(&["run", "nightly", "rustfmt", "--"]);
+ cmd
+ } else {
+ Command::new(rustfmt)
+ };
+
+ cmd
+ .args(&["--write-mode=display"])
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped());
- if let Some(path) = self.context
- .options()
+ if let Some(path) = self.options
.rustfmt_configuration_file
.as_ref()
.and_then(|f| f.to_str())
@@ -1562,34 +1726,52 @@ impl Bindings {
cmd.args(&["--config-path", path]);
}
- if let Ok(output) = cmd.arg(file).output() {
- if !output.status.success() {
- let stderr = String::from_utf8_lossy(&output.stderr);
- match output.status.code() {
- Some(2) => Err(io::Error::new(
- io::ErrorKind::Other,
- format!("Rustfmt parsing errors:\n{}", stderr),
- )),
- Some(3) => {
- warn!(
- "Rustfmt could not format some lines:\n{}",
- stderr
- );
- Ok(())
- }
- _ => Err(io::Error::new(
- io::ErrorKind::Other,
- format!("Internal rustfmt error:\n{}", stderr),
- )),
+ match cmd.spawn() {
+ Ok(mut child) => {
+ let mut child_stdin = child.stdin.take().unwrap();
+ let mut child_stdout = child.stdout.take().unwrap();
+
+ // Write to stdin in a new thread, so that we can read from stdout on this
+ // thread. This keeps the child from blocking on writing to its stdout which
+ // might block us from writing to its stdin.
+ let stdin_handle = ::std::thread::spawn(move || {
+ let _ = child_stdin.write_all(source.as_bytes());
+ source
+ });
+
+ let mut output = vec![];
+ io::copy(&mut child_stdout, &mut output)?;
+
+ let status = child.wait()?;
+ let source = stdin_handle.join()
+ .expect("The thread writing to rustfmt's stdin doesn't do \
+ anything that could panic");
+
+ match String::from_utf8(output) {
+ Ok(bindings) => {
+ match status.code() {
+ Some(0) => Ok(bindings),
+ Some(2) => Err(io::Error::new(
+ io::ErrorKind::Other,
+ "Rustfmt parsing errors.".to_string(),
+ )),
+ Some(3) => {
+ warn!("Rustfmt could not format some lines.");
+ Ok(bindings)
+ }
+ _ => Err(io::Error::new(
+ io::ErrorKind::Other,
+ "Internal rustfmt error".to_string(),
+ )),
+ }
+ },
+ _ => Ok(source)
}
- } else {
- Ok(())
}
- } else {
- Err(io::Error::new(
- io::ErrorKind::Other,
- "Error executing rustfmt!",
- ))
+ Err(e) => {
+ eprintln!("Error spawning rustfmt: {}", e);
+ Ok(source)
+ }
}
}
}
@@ -1601,7 +1783,7 @@ fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool {
}
/// Parse one `Item` from the Clang cursor.
-pub fn parse_one(
+fn parse_one(
ctx: &mut BindgenContext,
cursor: clang::Cursor,
parent: Option<ItemId>,
@@ -1629,7 +1811,7 @@ fn parse(context: &mut BindgenContext) -> Result<(), ()> {
for d in context.translation_unit().diags().iter() {
let msg = d.format();
let is_err = d.severity() >= CXDiagnostic_Error;
- println!("{}, err: {}", msg, is_err);
+ eprintln!("{}, err: {}", msg, is_err);
any_error |= is_err;
}
@@ -1729,8 +1911,8 @@ fn commandline_flag_unit_test_function() {
//Test 2
let bindings = ::builder()
.header("input_header")
- .whitelisted_type("Distinct_Type")
- .whitelisted_function("safe_function");
+ .whitelist_type("Distinct_Type")
+ .whitelist_function("safe_function");
let command_line_flags = bindings.command_line_flags();
let test_cases = vec![
diff --git a/src/options.rs b/src/options.rs
index e9fab3cc..10c31234 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -66,14 +66,18 @@ where
Arg::with_name("no-derive-debug")
.long("no-derive-debug")
.help("Avoid deriving Debug on any type."),
- Arg::with_name("impl-debug")
- .long("impl-debug")
- .help("Create Debug implementation, if it can not be derived \
- automatically."),
Arg::with_name("no-derive-default")
.long("no-derive-default")
.hidden(true)
.help("Avoid deriving Default on any type."),
+ Arg::with_name("impl-debug")
+ .long("impl-debug")
+ .help("Create Debug implementation, if it can not be derived \
+ automatically."),
+ Arg::with_name("impl-partialeq")
+ .long("impl-partialeq")
+ .help("Create PartialEq implementation, if it can not be derived \
+ automatically."),
Arg::with_name("with-derive-default")
.long("with-derive-default")
.help("Derive Default on any type."),
@@ -83,9 +87,17 @@ where
Arg::with_name("with-derive-partialeq")
.long("with-derive-partialeq")
.help("Derive partialeq on any type."),
+ Arg::with_name("with-derive-partialord")
+ .long("with-derive-partialord")
+ .help("Derive partialord on any type."),
Arg::with_name("with-derive-eq")
.long("with-derive-eq")
- .help("Derive eq on any type. Enable this option also enables --with-derive-partialeq"),
+ .help("Derive eq on any type. Enable this option also \
+ enables --with-derive-partialeq"),
+ Arg::with_name("with-derive-ord")
+ .long("with-derive-ord")
+ .help("Derive ord on any type. Enable this option also \
+ enables --with-derive-partialord"),
Arg::with_name("no-doc-comments")
.long("no-doc-comments")
.help("Avoid including doc comments in the output, see: \
@@ -249,19 +261,44 @@ where
Useful when debugging bindgen, using C-Reduce, or when \
filing issues. The resulting file will be named \
something like `__bindgen.i` or `__bindgen.ii`."),
+ Arg::with_name("no-rustfmt-bindings")
+ .long("no-rustfmt-bindings")
+ .help("Do not format the generated bindings with rustfmt."),
Arg::with_name("rustfmt-bindings")
.long("rustfmt-bindings")
- .help("Format the generated bindings with rustfmt. \
- Rustfmt needs to be in the global PATH."),
+ .help("Format the generated bindings with rustfmt. DEPRECATED: \
+ --rustfmt-bindings is now enabled by default. Disable \
+ with --no-rustfmt-bindings."),
Arg::with_name("rustfmt-configuration-file")
.long("rustfmt-configuration-file")
.help("The absolute path to the rustfmt configuration file. \
The configuration file will be used for formatting the bindings. \
- Setting this parameter, will automatically set --rustfmt-bindings.")
+ This parameter is incompatible with --no-rustfmt-bindings.")
.value_name("path")
.takes_value(true)
.multiple(false)
.number_of_values(1),
+ Arg::with_name("no-partialeq")
+ .long("no-partialeq")
+ .help("Avoid deriving PartialEq for types matching <regex>.")
+ .value_name("regex")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1),
+ Arg::with_name("no-copy")
+ .long("no-copy")
+ .help("Avoid deriving Copy for types matching <regex>.")
+ .value_name("regex")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1),
+ Arg::with_name("no-hash")
+ .long("no-hash")
+ .help("Avoid deriving Hash for types matching <regex>.")
+ .value_name("regex")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1),
]) // .args()
.get_matches_from(args);
@@ -304,7 +341,7 @@ where
}
if let Some(hidden_types) = matches.values_of("blacklist-type") {
for ty in hidden_types {
- builder = builder.hide_type(ty);
+ builder = builder.blacklist_type(ty);
}
}
@@ -328,6 +365,10 @@ where
builder = builder.impl_debug(true);
}
+ if matches.is_present("impl-partialeq") {
+ builder = builder.impl_partialeq(true);
+ }
+
if matches.is_present("with-derive-default") {
builder = builder.derive_default(true);
}
@@ -340,10 +381,18 @@ where
builder = builder.derive_partialeq(true);
}
+ if matches.is_present("with-derive-partialord") {
+ builder = builder.derive_partialord(true);
+ }
+
if matches.is_present("with-derive-eq") {
builder = builder.derive_eq(true);
}
+ if matches.is_present("with-derive-ord") {
+ builder = builder.derive_ord(true);
+ }
+
if matches.is_present("no-derive-default") {
builder = builder.derive_default(false);
}
@@ -479,7 +528,7 @@ where
if let Some(whitelist) = matches.values_of("whitelist-type") {
for regex in whitelist {
- builder = builder.whitelisted_type(regex);
+ builder = builder.whitelist_type(regex);
}
}
@@ -506,13 +555,21 @@ where
builder.dump_preprocessed_input()?;
}
- if matches.is_present("rustfmt-bindings") {
- builder = builder.rustfmt_bindings(true);
+ let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings");
+ if no_rustfmt_bindings {
+ builder = builder.rustfmt_bindings(false);
}
if let Some(path_str) = matches.value_of("rustfmt-configuration-file") {
let path = PathBuf::from(path_str);
+ if no_rustfmt_bindings {
+ return Err(Error::new(
+ ErrorKind::Other,
+ "Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings"
+ ));
+ }
+
if !path.is_absolute() {
return Err(Error::new(
ErrorKind::Other,
@@ -530,6 +587,24 @@ where
builder = builder.rustfmt_configuration_file(Some(path));
}
+ if let Some(no_partialeq) = matches.values_of("no-partialeq") {
+ for regex in no_partialeq {
+ builder = builder.no_partialeq(String::from(regex));
+ }
+ }
+
+ if let Some(no_copy) = matches.values_of("no-copy") {
+ for regex in no_copy {
+ builder = builder.no_copy(String::from(regex));
+ }
+ }
+
+ if let Some(no_hash) = matches.values_of("no-hash") {
+ for regex in no_hash {
+ builder = builder.no_hash(String::from(regex));
+ }
+ }
+
let verbose = matches.is_present("verbose");
Ok((builder, output, verbose))
diff --git a/src/parse.rs b/src/parse.rs
index 5869f302..1a9278b3 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -1,7 +1,7 @@
//! Common traits and types related to parsing our IR from Clang cursors.
use clang;
-use ir::context::{BindgenContext, ItemId};
+use ir::context::{BindgenContext, ItemId, TypeId};
use ir::ty::TypeKind;
/// Not so much an error in the traditional sense, but a control flow message
@@ -55,7 +55,7 @@ pub trait ClangItemParser: Sized {
location: clang::Cursor,
parent: Option<ItemId>,
ctx: &mut BindgenContext,
- ) -> Result<ItemId, ParseError>;
+ ) -> Result<TypeId, ParseError>;
/// Identical to `from_ty`, but use the given `id` as the `ItemId` for the
/// newly parsed item.
@@ -65,7 +65,7 @@ pub trait ClangItemParser: Sized {
location: clang::Cursor,
parent: Option<ItemId>,
ctx: &mut BindgenContext,
- ) -> Result<ItemId, ParseError>;
+ ) -> Result<TypeId, ParseError>;
/// Parse this item from the given Clang type, or if we haven't resolved all
/// the other items this one depends on, an unresolved reference.
@@ -74,7 +74,7 @@ pub trait ClangItemParser: Sized {
location: clang::Cursor,
parent_id: Option<ItemId>,
context: &mut BindgenContext,
- ) -> ItemId;
+ ) -> TypeId;
/// Identical to `from_ty_or_ref`, but use the given `potential_id` as the
/// `ItemId` for the newly parsed item.
@@ -84,19 +84,19 @@ pub trait ClangItemParser: Sized {
location: clang::Cursor,
parent_id: Option<ItemId>,
context: &mut BindgenContext,
- ) -> ItemId;
+ ) -> TypeId;
/// Create a named template type.
fn type_param(
with_id: Option<ItemId>,
location: clang::Cursor,
ctx: &mut BindgenContext,
- ) -> Option<ItemId>;
+ ) -> Option<TypeId>;
/// Create a builtin type.
fn builtin_type(
kind: TypeKind,
is_const: bool,
context: &mut BindgenContext,
- ) -> ItemId;
+ ) -> TypeId;
}
diff --git a/src/regex_set.rs b/src/regex_set.rs
index a6f51336..8bd3ea7f 100644
--- a/src/regex_set.rs
+++ b/src/regex_set.rs
@@ -18,17 +18,6 @@ impl RegexSet {
self.items.is_empty()
}
- /// Extend this set with every regex in the iterator.
- pub fn extend<I, S>(&mut self, iter: I)
- where
- I: IntoIterator<Item = S>,
- S: AsRef<str>,
- {
- for s in iter.into_iter() {
- self.insert(s)
- }
- }
-
/// Insert a new regex into this set.
pub fn insert<S>(&mut self, string: S)
where
@@ -42,10 +31,6 @@ impl RegexSet {
pub fn get_items(&self) -> &[String] {
&self.items[..]
}
- /// Returns reference of its field 'set'
- pub fn get_set(&self) -> Option<&RxSet> {
- self.set.as_ref()
- }
/// Construct a RegexSet from the set of entries we've accumulated.
///
diff --git a/tests/expectations/struct_with_anon_struct_array_float.rs b/tests/expectations/struct_with_anon_struct_array_float.rs
index e69de29b..8b137891 100644
--- a/tests/expectations/struct_with_anon_struct_array_float.rs
+++ b/tests/expectations/struct_with_anon_struct_array_float.rs
@@ -0,0 +1 @@
+
diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs
index 86103656..57bc753d 100644
--- a/tests/expectations/tests/16-byte-alignment.rs
+++ b/tests/expectations/tests/16-byte-alignment.rs
@@ -5,193 +5,265 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
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(Copy)]
+#[derive(Copy, Clone)]
pub union rte_ipv4_tuple__bindgen_ty_1 {
pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1,
pub sctp_tag: u32,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 4usize , concat ! (
- "Size of: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 2usize , concat ! (
- "Alignment of " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . dport as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( dport ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . sport as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( sport ) ));
-}
-impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!(
+ "Alignment of ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(dport)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
+ },
+ 2usize,
+ concat!(
+ "Alignment 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() {
- assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>() , 4usize
- , concat ! (
- "Size of: " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1 ) ) .
- sctp_tag as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag
- ) ));
-}
-impl Clone for rte_ipv4_tuple__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1),
+ "::",
+ stringify!(sctp_tag)
+ )
+ );
}
impl Default for rte_ipv4_tuple__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_rte_ipv4_tuple() {
- assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize , concat ! (
- "Size of: " , stringify ! ( rte_ipv4_tuple ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv4_tuple>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv4_tuple ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv4_tuple ) ) . src_addr as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::"
- , stringify ! ( src_addr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv4_tuple ) ) . dst_addr as * const
- _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::"
- , stringify ! ( dst_addr ) ));
-}
-impl Clone for rte_ipv4_tuple {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv4_tuple>(),
+ 12usize,
+ concat!("Size of: ", stringify!(rte_ipv4_tuple))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv4_tuple>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv4_tuple))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv4_tuple)).src_addr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple),
+ "::",
+ stringify!(src_addr)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv4_tuple)).dst_addr as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple),
+ "::",
+ stringify!(dst_addr)
+ )
+ );
}
impl Default for rte_ipv4_tuple {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
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(Copy)]
+#[derive(Copy, Clone)]
pub union rte_ipv6_tuple__bindgen_ty_1 {
pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1,
pub sctp_tag: u32,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 4usize , concat ! (
- "Size of: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 2usize , concat ! (
- "Alignment of " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . dport as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( dport ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . sport as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( sport ) ));
-}
-impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!(
+ "Alignment of ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(dport)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
+ },
+ 2usize,
+ concat!(
+ "Alignment 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() {
- assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>() , 4usize
- , concat ! (
- "Size of: " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1 ) ) .
- sctp_tag as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag
- ) ));
-}
-impl Clone for rte_ipv6_tuple__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1),
+ "::",
+ stringify!(sctp_tag)
+ )
+ );
}
impl Default for rte_ipv6_tuple__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_rte_ipv6_tuple() {
- assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize , concat ! (
- "Size of: " , stringify ! ( rte_ipv6_tuple ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv6_tuple>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv6_tuple ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv6_tuple ) ) . src_addr as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::"
- , stringify ! ( src_addr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv6_tuple ) ) . dst_addr as * const
- _ as usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::"
- , stringify ! ( dst_addr ) ));
-}
-impl Clone for rte_ipv6_tuple {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv6_tuple>(),
+ 36usize,
+ concat!("Size of: ", stringify!(rte_ipv6_tuple))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv6_tuple>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv6_tuple))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv6_tuple)).src_addr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple),
+ "::",
+ stringify!(src_addr)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv6_tuple)).dst_addr as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple),
+ "::",
+ stringify!(dst_addr)
+ )
+ );
}
impl Default for rte_ipv6_tuple {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_thash_tuple {
pub v4: rte_ipv4_tuple,
pub v6: rte_ipv6_tuple,
@@ -199,22 +271,34 @@ pub union rte_thash_tuple {
}
#[test]
fn bindgen_test_layout_rte_thash_tuple() {
- assert_eq!(::std::mem::size_of::<rte_thash_tuple>() , 48usize , concat ! (
- "Size of: " , stringify ! ( rte_thash_tuple ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_thash_tuple ) ) . v4 as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_thash_tuple ) ,
- "::" , stringify ! ( v4 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_thash_tuple ) ) . v6 as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_thash_tuple ) ,
- "::" , stringify ! ( v6 ) ));
-}
-impl Clone for rte_thash_tuple {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_thash_tuple>(),
+ 48usize,
+ concat!("Size of: ", stringify!(rte_thash_tuple))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_thash_tuple)).v4 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_thash_tuple),
+ "::",
+ stringify!(v4)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_thash_tuple)).v6 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_thash_tuple),
+ "::",
+ stringify!(v6)
+ )
+ );
}
impl Default for rte_thash_tuple {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs
index 98cb1a49..712bc519 100644
--- a/tests/expectations/tests/16-byte-alignment_1_0.rs
+++ b/tests/expectations/tests/16-byte-alignment_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct rte_ipv4_tuple {
@@ -57,70 +69,117 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 4usize , concat ! (
- "Size of: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 2usize , concat ! (
- "Alignment of " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . dport as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( dport ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . sport as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( sport ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!(
+ "Alignment of ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(dport)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
+ },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(sport)
+ )
+ );
}
impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>() , 4usize
- , concat ! (
- "Size of: " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1 ) ) .
- sctp_tag as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv4_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag
- ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple__bindgen_ty_1),
+ "::",
+ stringify!(sctp_tag)
+ )
+ );
}
impl Clone for rte_ipv4_tuple__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_rte_ipv4_tuple() {
- assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize , concat ! (
- "Size of: " , stringify ! ( rte_ipv4_tuple ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv4_tuple>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv4_tuple ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv4_tuple ) ) . src_addr as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::"
- , stringify ! ( src_addr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv4_tuple ) ) . dst_addr as * const
- _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::"
- , stringify ! ( dst_addr ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv4_tuple>(),
+ 12usize,
+ concat!("Size of: ", stringify!(rte_ipv4_tuple))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv4_tuple>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv4_tuple))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv4_tuple)).src_addr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple),
+ "::",
+ stringify!(src_addr)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv4_tuple)).dst_addr as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv4_tuple),
+ "::",
+ stringify!(dst_addr)
+ )
+ );
}
impl Clone for rte_ipv4_tuple {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -144,70 +203,117 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 4usize , concat ! (
- "Size of: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>()
- , 2usize , concat ! (
- "Alignment of " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . dport as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( dport ) ));
- assert_eq! (unsafe {
- & (
- * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 )
- ) . sport as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" ,
- stringify ! ( sport ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!(
+ "Alignment of ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(dport)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
+ },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(sport)
+ )
+ );
}
impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>() , 4usize
- , concat ! (
- "Size of: " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1 ) ) .
- sctp_tag as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- rte_ipv6_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag
- ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple__bindgen_ty_1),
+ "::",
+ stringify!(sctp_tag)
+ )
+ );
}
impl Clone for rte_ipv6_tuple__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_rte_ipv6_tuple() {
- assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize , concat ! (
- "Size of: " , stringify ! ( rte_ipv6_tuple ) ));
- assert_eq! (::std::mem::align_of::<rte_ipv6_tuple>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ipv6_tuple ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv6_tuple ) ) . src_addr as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::"
- , stringify ! ( src_addr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ipv6_tuple ) ) . dst_addr as * const
- _ as usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::"
- , stringify ! ( dst_addr ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ipv6_tuple>(),
+ 36usize,
+ concat!("Size of: ", stringify!(rte_ipv6_tuple))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ipv6_tuple>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ipv6_tuple))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv6_tuple)).src_addr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple),
+ "::",
+ stringify!(src_addr)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ipv6_tuple)).dst_addr as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ipv6_tuple),
+ "::",
+ stringify!(dst_addr)
+ )
+ );
}
impl Clone for rte_ipv6_tuple {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Copy)]
@@ -218,22 +324,39 @@ pub struct rte_thash_tuple {
}
#[test]
fn bindgen_test_layout_rte_thash_tuple() {
- assert_eq!(::std::mem::size_of::<rte_thash_tuple>() , 48usize , concat ! (
- "Size of: " , stringify ! ( rte_thash_tuple ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_thash_tuple ) ) . v4 as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_thash_tuple ) ,
- "::" , stringify ! ( v4 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_thash_tuple ) ) . v6 as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_thash_tuple ) ,
- "::" , stringify ! ( v6 ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_thash_tuple>(),
+ 48usize,
+ concat!("Size of: ", stringify!(rte_thash_tuple))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_thash_tuple)).v4 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_thash_tuple),
+ "::",
+ stringify!(v4)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_thash_tuple)).v6 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_thash_tuple),
+ "::",
+ stringify!(v6)
+ )
+ );
}
impl Clone for rte_thash_tuple {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for rte_thash_tuple {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs
index df1732c4..ac2fb747 100644
--- a/tests/expectations/tests/accessors.rs
+++ b/tests/expectations/tests/accessors.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct SomeAccessors {
pub mNoAccessor: ::std::os::raw::c_int,
/// <div rustbindgen accessor></div>
@@ -17,33 +17,56 @@ pub struct SomeAccessors {
}
#[test]
fn bindgen_test_layout_SomeAccessors() {
- assert_eq!(::std::mem::size_of::<SomeAccessors>() , 16usize , concat ! (
- "Size of: " , stringify ! ( SomeAccessors ) ));
- assert_eq! (::std::mem::align_of::<SomeAccessors>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( SomeAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const SomeAccessors ) ) . mNoAccessor as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( SomeAccessors ) , "::"
- , stringify ! ( mNoAccessor ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const SomeAccessors ) ) . mBothAccessors as *
- const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( SomeAccessors ) , "::"
- , stringify ! ( mBothAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const SomeAccessors ) ) . mUnsafeAccessors as *
- const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( SomeAccessors ) , "::"
- , stringify ! ( mUnsafeAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const SomeAccessors ) ) . mImmutableAccessor as
- * const _ as usize } , 12usize , concat ! (
- "Alignment of field: " , stringify ! ( SomeAccessors ) , "::"
- , stringify ! ( mImmutableAccessor ) ));
-}
-impl Clone for SomeAccessors {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<SomeAccessors>(),
+ 16usize,
+ concat!("Size of: ", stringify!(SomeAccessors))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<SomeAccessors>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(SomeAccessors))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const SomeAccessors)).mNoAccessor as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(SomeAccessors),
+ "::",
+ stringify!(mNoAccessor)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const SomeAccessors)).mBothAccessors as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(SomeAccessors),
+ "::",
+ stringify!(mBothAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const SomeAccessors)).mUnsafeAccessors as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(SomeAccessors),
+ "::",
+ stringify!(mUnsafeAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const SomeAccessors)).mImmutableAccessor as *const _ as usize },
+ 12usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(SomeAccessors),
+ "::",
+ stringify!(mImmutableAccessor)
+ )
+ );
}
impl SomeAccessors {
#[inline]
@@ -59,8 +82,7 @@ impl SomeAccessors {
&self.mUnsafeAccessors
}
#[inline]
- pub unsafe fn get_mUnsafeAccessors_mut(&mut self)
- -> &mut ::std::os::raw::c_int {
+ pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int {
&mut self.mUnsafeAccessors
}
#[inline]
@@ -70,30 +92,43 @@ impl SomeAccessors {
}
/// <div rustbindgen accessor></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct AllAccessors {
pub mBothAccessors: ::std::os::raw::c_int,
pub mAlsoBothAccessors: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_AllAccessors() {
- assert_eq!(::std::mem::size_of::<AllAccessors>() , 8usize , concat ! (
- "Size of: " , stringify ! ( AllAccessors ) ));
- assert_eq! (::std::mem::align_of::<AllAccessors>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( AllAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const AllAccessors ) ) . mBothAccessors as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( AllAccessors ) , "::" ,
- stringify ! ( mBothAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const AllAccessors ) ) . mAlsoBothAccessors as
- * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( AllAccessors ) , "::" ,
- stringify ! ( mAlsoBothAccessors ) ));
-}
-impl Clone for AllAccessors {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<AllAccessors>(),
+ 8usize,
+ concat!("Size of: ", stringify!(AllAccessors))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<AllAccessors>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(AllAccessors))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const AllAccessors)).mBothAccessors as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(AllAccessors),
+ "::",
+ stringify!(mBothAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const AllAccessors)).mAlsoBothAccessors as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(AllAccessors),
+ "::",
+ stringify!(mAlsoBothAccessors)
+ )
+ );
}
impl AllAccessors {
#[inline]
@@ -109,38 +144,49 @@ impl AllAccessors {
&self.mAlsoBothAccessors
}
#[inline]
- pub fn get_mAlsoBothAccessors_mut(&mut self)
- -> &mut ::std::os::raw::c_int {
+ pub fn get_mAlsoBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int {
&mut self.mAlsoBothAccessors
}
}
/// <div rustbindgen accessor="unsafe"></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct AllUnsafeAccessors {
pub mBothAccessors: ::std::os::raw::c_int,
pub mAlsoBothAccessors: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_AllUnsafeAccessors() {
- assert_eq!(::std::mem::size_of::<AllUnsafeAccessors>() , 8usize , concat !
- ( "Size of: " , stringify ! ( AllUnsafeAccessors ) ));
- assert_eq! (::std::mem::align_of::<AllUnsafeAccessors>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( AllUnsafeAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const AllUnsafeAccessors ) ) . mBothAccessors
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( AllUnsafeAccessors ) ,
- "::" , stringify ! ( mBothAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const AllUnsafeAccessors ) ) .
- mAlsoBothAccessors as * const _ as usize } , 4usize , concat !
- (
- "Alignment of field: " , stringify ! ( AllUnsafeAccessors ) ,
- "::" , stringify ! ( mAlsoBothAccessors ) ));
-}
-impl Clone for AllUnsafeAccessors {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<AllUnsafeAccessors>(),
+ 8usize,
+ concat!("Size of: ", stringify!(AllUnsafeAccessors))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<AllUnsafeAccessors>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(AllUnsafeAccessors))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const AllUnsafeAccessors)).mBothAccessors as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(AllUnsafeAccessors),
+ "::",
+ stringify!(mBothAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const AllUnsafeAccessors)).mAlsoBothAccessors as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(AllUnsafeAccessors),
+ "::",
+ stringify!(mAlsoBothAccessors)
+ )
+ );
}
impl AllUnsafeAccessors {
#[inline]
@@ -148,8 +194,7 @@ impl AllUnsafeAccessors {
&self.mBothAccessors
}
#[inline]
- pub unsafe fn get_mBothAccessors_mut(&mut self)
- -> &mut ::std::os::raw::c_int {
+ pub unsafe fn get_mBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int {
&mut self.mBothAccessors
}
#[inline]
@@ -157,14 +202,13 @@ impl AllUnsafeAccessors {
&self.mAlsoBothAccessors
}
#[inline]
- pub unsafe fn get_mAlsoBothAccessors_mut(&mut self)
- -> &mut ::std::os::raw::c_int {
+ pub unsafe fn get_mAlsoBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int {
&mut self.mAlsoBothAccessors
}
}
/// <div rustbindgen accessor></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct ContradictAccessors {
pub mBothAccessors: ::std::os::raw::c_int,
/// <div rustbindgen accessor="false"></div>
@@ -176,35 +220,56 @@ pub struct ContradictAccessors {
}
#[test]
fn bindgen_test_layout_ContradictAccessors() {
- assert_eq!(::std::mem::size_of::<ContradictAccessors>() , 16usize , concat
- ! ( "Size of: " , stringify ! ( ContradictAccessors ) ));
- assert_eq! (::std::mem::align_of::<ContradictAccessors>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( ContradictAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContradictAccessors ) ) . mBothAccessors
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ContradictAccessors ) ,
- "::" , stringify ! ( mBothAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContradictAccessors ) ) . mNoAccessors as
- * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( ContradictAccessors ) ,
- "::" , stringify ! ( mNoAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContradictAccessors ) ) .
- mUnsafeAccessors as * const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( ContradictAccessors ) ,
- "::" , stringify ! ( mUnsafeAccessors ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContradictAccessors ) ) .
- mImmutableAccessor as * const _ as usize } , 12usize , concat
- ! (
- "Alignment of field: " , stringify ! ( ContradictAccessors ) ,
- "::" , stringify ! ( mImmutableAccessor ) ));
-}
-impl Clone for ContradictAccessors {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ContradictAccessors>(),
+ 16usize,
+ concat!("Size of: ", stringify!(ContradictAccessors))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ContradictAccessors>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ContradictAccessors))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContradictAccessors)).mBothAccessors as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContradictAccessors),
+ "::",
+ stringify!(mBothAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContradictAccessors)).mNoAccessors as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContradictAccessors),
+ "::",
+ stringify!(mNoAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContradictAccessors)).mUnsafeAccessors as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContradictAccessors),
+ "::",
+ stringify!(mUnsafeAccessors)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContradictAccessors)).mImmutableAccessor as *const _ as usize },
+ 12usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContradictAccessors),
+ "::",
+ stringify!(mImmutableAccessor)
+ )
+ );
}
impl ContradictAccessors {
#[inline]
@@ -220,8 +285,7 @@ impl ContradictAccessors {
&self.mUnsafeAccessors
}
#[inline]
- pub unsafe fn get_mUnsafeAccessors_mut(&mut self)
- -> &mut ::std::os::raw::c_int {
+ pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int {
&mut self.mUnsafeAccessors
}
#[inline]
@@ -231,28 +295,38 @@ impl ContradictAccessors {
}
/// <div rustbindgen accessor replaces="Replaced"></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Replaced {
pub mAccessor: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Replaced() {
- assert_eq!(::std::mem::size_of::<Replaced>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Replaced ) ));
- assert_eq! (::std::mem::align_of::<Replaced>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Replaced ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Replaced ) ) . mAccessor as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Replaced ) , "::" ,
- stringify ! ( mAccessor ) ));
-}
-impl Clone for Replaced {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Replaced>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Replaced))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Replaced>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Replaced))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Replaced)).mAccessor as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Replaced),
+ "::",
+ stringify!(mAccessor)
+ )
+ );
}
impl Replaced {
#[inline]
- pub fn get_mAccessor(&self) -> &::std::os::raw::c_int { &self.mAccessor }
+ pub fn get_mAccessor(&self) -> &::std::os::raw::c_int {
+ &self.mAccessor
+ }
#[inline]
pub fn get_mAccessor_mut(&mut self) -> &mut ::std::os::raw::c_int {
&mut self.mAccessor
@@ -260,28 +334,38 @@ impl Replaced {
}
/// <div rustbindgen accessor></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Wrapper {
pub mReplaced: Replaced,
}
#[test]
fn bindgen_test_layout_Wrapper() {
- assert_eq!(::std::mem::size_of::<Wrapper>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Wrapper ) ));
- assert_eq! (::std::mem::align_of::<Wrapper>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Wrapper ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Wrapper ) ) . mReplaced as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Wrapper ) , "::" ,
- stringify ! ( mReplaced ) ));
-}
-impl Clone for Wrapper {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Wrapper>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Wrapper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Wrapper>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Wrapper))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Wrapper)).mReplaced as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Wrapper),
+ "::",
+ stringify!(mReplaced)
+ )
+ );
}
impl Wrapper {
#[inline]
- pub fn get_mReplaced(&self) -> &Replaced { &self.mReplaced }
+ pub fn get_mReplaced(&self) -> &Replaced {
+ &self.mReplaced
+ }
#[inline]
pub fn get_mReplaced_mut(&mut self) -> &mut Replaced {
&mut self.mReplaced
diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs
index 0cd443a7..7f68d115 100644
--- a/tests/expectations/tests/annotation_hide.rs
+++ b/tests/expectations/tests/annotation_hide.rs
@@ -7,7 +7,7 @@
/// <div rustbindgen opaque></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct D {
pub _bindgen_opaque_blob: u32,
}
@@ -24,13 +24,8 @@ fn bindgen_test_layout_D() {
concat!("Alignment of ", stringify!(D))
);
}
-impl Clone for D {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct NotAnnotated {
pub f: ::std::os::raw::c_int,
}
@@ -57,8 +52,3 @@ fn bindgen_test_layout_NotAnnotated() {
)
);
}
-impl Clone for NotAnnotated {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs
index b1004274..3dfd5ad3 100644
--- a/tests/expectations/tests/anon_enum.rs
+++ b/tests/expectations/tests/anon_enum.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct Test {
pub foo: ::std::os::raw::c_int,
pub bar: f32,
@@ -13,27 +13,45 @@ pub struct Test {
pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Test__bindgen_ty_1 { T_NONE = 0, }
+pub enum Test__bindgen_ty_1 {
+ T_NONE = 0,
+}
#[test]
fn bindgen_test_layout_Test() {
- assert_eq!(::std::mem::size_of::<Test>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Test ) ));
- assert_eq! (::std::mem::align_of::<Test>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Test ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . foo as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . bar as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for Test {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Test))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).foo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(foo)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).bar as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(bar)
+ )
+ );
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Baz { Foo = 0, Bar = 1, }
+pub enum Baz {
+ Foo = 0,
+ Bar = 1,
+}
diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs
index f0c1d364..9f5a6c56 100644
--- a/tests/expectations/tests/anon_enum_trait.rs
+++ b/tests/expectations/tests/anon_enum_trait.rs
@@ -13,21 +13,18 @@ pub type DataType_value_type<_Tp> = _Tp;
pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>;
pub type DataType_channel_type<_Tp> = DataType_value_type<_Tp>;
pub type DataType_vec_type<_Tp> = DataType_value_type<_Tp>;
-pub const DataType_generic_type: DataType__bindgen_ty_1 =
- DataType__bindgen_ty_1::generic_type;
-pub const DataType_depth: DataType__bindgen_ty_1 =
- DataType__bindgen_ty_1::generic_type;
-pub const DataType_channels: DataType__bindgen_ty_1 =
- DataType__bindgen_ty_1::generic_type;
-pub const DataType_fmt: DataType__bindgen_ty_1 =
- DataType__bindgen_ty_1::generic_type;
-pub const DataType_type_: DataType__bindgen_ty_1 =
- DataType__bindgen_ty_1::generic_type;
+pub const DataType_generic_type: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
+pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
+pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
+pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
+pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum DataType__bindgen_ty_1 { generic_type = 0, }
+pub enum DataType__bindgen_ty_1 {
+ generic_type = 0,
+}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Foo {
pub _address: u8,
}
@@ -35,14 +32,19 @@ pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo__bindgen_ty_1 { Bar = 0, }
+pub enum Foo__bindgen_ty_1 {
+ Bar = 0,
+}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/anon_enum_whitelist.rs b/tests/expectations/tests/anon_enum_whitelist.rs
index d3f54275..c639410f 100644
--- a/tests/expectations/tests/anon_enum_whitelist.rs
+++ b/tests/expectations/tests/anon_enum_whitelist.rs
@@ -8,4 +8,7 @@ pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO;
pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _bindgen_ty_1 { NODE_FLAG_FOO = 0, NODE_FLAG_BAR = 1, }
+pub enum _bindgen_ty_1 {
+ NODE_FLAG_FOO = 0,
+ NODE_FLAG_BAR = 1,
+}
diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs
index 783a62cf..4a5054f6 100644
--- a/tests/expectations/tests/anon_struct_in_union.rs
+++ b/tests/expectations/tests/anon_struct_in_union.rs
@@ -5,70 +5,92 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct s {
pub u: s__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union s__bindgen_ty_1 {
pub field: s__bindgen_ty_1_inner,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<s__bindgen_ty_1_inner>() , 4usize ,
- concat ! ( "Size of: " , stringify ! ( s__bindgen_ty_1_inner )
- ));
- assert_eq! (::std::mem::align_of::<s__bindgen_ty_1_inner>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( s__bindgen_ty_1_inner ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const s__bindgen_ty_1_inner ) ) . b as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( s__bindgen_ty_1_inner )
- , "::" , stringify ! ( b ) ));
-}
-impl Clone for s__bindgen_ty_1_inner {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<s__bindgen_ty_1_inner>(),
+ 4usize,
+ concat!("Size of: ", stringify!(s__bindgen_ty_1_inner))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<s__bindgen_ty_1_inner>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const s__bindgen_ty_1_inner)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(s__bindgen_ty_1_inner),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[test]
fn bindgen_test_layout_s__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<s__bindgen_ty_1>() , 4usize , concat ! (
- "Size of: " , stringify ! ( s__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<s__bindgen_ty_1>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( s__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const s__bindgen_ty_1 ) ) . field as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( s__bindgen_ty_1 ) ,
- "::" , stringify ! ( field ) ));
-}
-impl Clone for s__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<s__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(s__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<s__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(s__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const s__bindgen_ty_1)).field as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(s__bindgen_ty_1),
+ "::",
+ stringify!(field)
+ )
+ );
}
impl Default for s__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_s() {
- assert_eq!(::std::mem::size_of::<s>() , 4usize , concat ! (
- "Size of: " , stringify ! ( s ) ));
- assert_eq! (::std::mem::align_of::<s>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( s ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const s ) ) . u as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( s ) , "::" , stringify
- ! ( u ) ));
-}
-impl Clone for s {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<s>(),
+ 4usize,
+ concat!("Size of: ", stringify!(s))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<s>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(s))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const s)).u as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(s), "::", stringify!(u))
+ );
}
impl Default for s {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs
index 8c29f8e4..8e2e6bea 100644
--- a/tests/expectations/tests/anon_struct_in_union_1_0.rs
+++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct s {
@@ -53,47 +65,80 @@ pub struct s__bindgen_ty_1_inner {
}
#[test]
fn bindgen_test_layout_s__bindgen_ty_1_inner() {
- assert_eq!(::std::mem::size_of::<s__bindgen_ty_1_inner>() , 4usize ,
- concat ! ( "Size of: " , stringify ! ( s__bindgen_ty_1_inner )
- ));
- assert_eq! (::std::mem::align_of::<s__bindgen_ty_1_inner>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( s__bindgen_ty_1_inner ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const s__bindgen_ty_1_inner ) ) . b as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( s__bindgen_ty_1_inner )
- , "::" , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<s__bindgen_ty_1_inner>(),
+ 4usize,
+ concat!("Size of: ", stringify!(s__bindgen_ty_1_inner))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<s__bindgen_ty_1_inner>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const s__bindgen_ty_1_inner)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(s__bindgen_ty_1_inner),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for s__bindgen_ty_1_inner {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_s__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<s__bindgen_ty_1>() , 4usize , concat ! (
- "Size of: " , stringify ! ( s__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<s__bindgen_ty_1>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( s__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const s__bindgen_ty_1 ) ) . field as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( s__bindgen_ty_1 ) ,
- "::" , stringify ! ( field ) ));
+ assert_eq!(
+ ::std::mem::size_of::<s__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(s__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<s__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(s__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const s__bindgen_ty_1)).field as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(s__bindgen_ty_1),
+ "::",
+ stringify!(field)
+ )
+ );
}
impl Clone for s__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_s() {
- assert_eq!(::std::mem::size_of::<s>() , 4usize , concat ! (
- "Size of: " , stringify ! ( s ) ));
- assert_eq! (::std::mem::align_of::<s>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( s ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const s ) ) . u as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( s ) , "::" , stringify
- ! ( u ) ));
+ assert_eq!(
+ ::std::mem::size_of::<s>(),
+ 4usize,
+ concat!("Size of: ", stringify!(s))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<s>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(s))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const s)).u as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(s), "::", stringify!(u))
+ );
}
impl Clone for s {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs
index f2da118d..fdf01a7a 100644
--- a/tests/expectations/tests/anon_union.rs
+++ b/tests/expectations/tests/anon_union.rs
@@ -15,7 +15,9 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
TErrorResult_UnionState::HasMessage;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum TErrorResult_UnionState { HasMessage = 0, }
+pub enum TErrorResult_UnionState {
+ HasMessage = 0,
+}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct TErrorResult_Message {
@@ -33,10 +35,14 @@ pub union TErrorResult__bindgen_ty_1 {
_bindgen_union_align: u64,
}
impl Default for TErrorResult__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl Default for TErrorResult {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct ErrorResult {
@@ -44,20 +50,38 @@ pub struct ErrorResult {
}
#[test]
fn bindgen_test_layout_ErrorResult() {
- assert_eq!(::std::mem::size_of::<ErrorResult>() , 24usize , concat ! (
- "Size of: " , stringify ! ( ErrorResult ) ));
- assert_eq! (::std::mem::align_of::<ErrorResult>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ErrorResult ) ));
+ assert_eq!(
+ ::std::mem::size_of::<ErrorResult>(),
+ 24usize,
+ concat!("Size of: ", stringify!(ErrorResult))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ErrorResult>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ErrorResult))
+ );
}
impl Default for ErrorResult {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! (
- "Size of template specialization: " , stringify ! (
- TErrorResult ) ));
- assert_eq!(::std::mem::align_of::<TErrorResult>() , 8usize , concat ! (
- "Alignment of template specialization: " , stringify ! (
- TErrorResult ) ));
+ assert_eq!(
+ ::std::mem::size_of::<TErrorResult>(),
+ 24usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(TErrorResult)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TErrorResult>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(TErrorResult)
+ )
+ );
}
diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs
index b96928d4..8d19c9fc 100644
--- a/tests/expectations/tests/anon_union_1_0.rs
+++ b/tests/expectations/tests/anon_union_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct TErrorResult {
@@ -47,7 +59,9 @@ pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState =
TErrorResult_UnionState::HasMessage;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum TErrorResult_UnionState { HasMessage = 0, }
+pub enum TErrorResult_UnionState {
+ HasMessage = 0,
+}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct TErrorResult_Message {
@@ -66,7 +80,9 @@ pub struct TErrorResult__bindgen_ty_1 {
pub bindgen_union_field: u64,
}
impl Default for TErrorResult {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
@@ -75,23 +91,43 @@ pub struct ErrorResult {
}
#[test]
fn bindgen_test_layout_ErrorResult() {
- assert_eq!(::std::mem::size_of::<ErrorResult>() , 24usize , concat ! (
- "Size of: " , stringify ! ( ErrorResult ) ));
- assert_eq! (::std::mem::align_of::<ErrorResult>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ErrorResult ) ));
+ assert_eq!(
+ ::std::mem::size_of::<ErrorResult>(),
+ 24usize,
+ concat!("Size of: ", stringify!(ErrorResult))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ErrorResult>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ErrorResult))
+ );
}
impl Clone for ErrorResult {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for ErrorResult {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! (
- "Size of template specialization: " , stringify ! (
- TErrorResult ) ));
- assert_eq!(::std::mem::align_of::<TErrorResult>() , 8usize , concat ! (
- "Alignment of template specialization: " , stringify ! (
- TErrorResult ) ));
+ assert_eq!(
+ ::std::mem::size_of::<TErrorResult>(),
+ 24usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(TErrorResult)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TErrorResult>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(TErrorResult)
+ )
+ );
}
diff --git a/tests/expectations/tests/anonymous-template-types.rs b/tests/expectations/tests/anonymous-template-types.rs
index 532e2427..0fedfe45 100644
--- a/tests/expectations/tests/anonymous-template-types.rs
+++ b/tests/expectations/tests/anonymous-template-types.rs
@@ -10,8 +10,10 @@ pub struct Foo<T> {
pub t_member: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Foo<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Foo<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
@@ -24,8 +26,10 @@ pub struct Quux<V> {
pub v_member: V,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<V>>,
}
-impl <V> Default for Quux<V> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<V> Default for Quux<V> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
diff --git a/tests/expectations/tests/arg_keyword.rs b/tests/expectations/tests/arg_keyword.rs
index 8406eaab..54c036d8 100644
--- a/tests/expectations/tests/arg_keyword.rs
+++ b/tests/expectations/tests/arg_keyword.rs
@@ -5,6 +5,6 @@
extern "C" {
- #[link_name = "_Z3fooPKc"]
+ #[link_name = "\u{1}_Z3fooPKc"]
pub fn foo(type_: *const ::std::os::raw::c_char);
}
diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs
new file mode 100644
index 00000000..92fbeadf
--- /dev/null
+++ b/tests/expectations/tests/array-of-zero-sized-types.rs
@@ -0,0 +1,56 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+
+/// This should get an `_address` byte.
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Empty {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_Empty() {
+ assert_eq!(
+ ::std::mem::size_of::<Empty>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Empty))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Empty>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Empty))
+ );
+}
+/// This should not get an `_address` byte, since each `Empty` gets one, meaning
+/// that this object is addressable.
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct HasArrayOfEmpty {
+ pub empties: [Empty; 10usize],
+}
+#[test]
+fn bindgen_test_layout_HasArrayOfEmpty() {
+ assert_eq!(
+ ::std::mem::size_of::<HasArrayOfEmpty>(),
+ 10usize,
+ concat!("Size of: ", stringify!(HasArrayOfEmpty))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<HasArrayOfEmpty>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(HasArrayOfEmpty))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const HasArrayOfEmpty)).empties as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(HasArrayOfEmpty),
+ "::",
+ stringify!(empties)
+ )
+ );
+}
diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs
index 3bd9bec0..901bec60 100644
--- a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs
+++ b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs
@@ -10,7 +10,9 @@ pub struct std_char_traits {
pub _address: u8,
}
impl Default for std_char_traits {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
diff --git a/tests/expectations/tests/base-to-derived.rs b/tests/expectations/tests/base-to-derived.rs
index 0a9e1c35..9df54d98 100644
--- a/tests/expectations/tests/base-to-derived.rs
+++ b/tests/expectations/tests/base-to-derived.rs
@@ -5,17 +5,20 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct false_type {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_false_type() {
- assert_eq!(::std::mem::size_of::<false_type>() , 1usize , concat ! (
- "Size of: " , stringify ! ( false_type ) ));
- assert_eq! (::std::mem::align_of::<false_type>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( false_type ) ));
-}
-impl Clone for false_type {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<false_type>(),
+ 1usize,
+ concat!("Size of: ", stringify!(false_type))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<false_type>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(false_type))
+ );
}
diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs
index 9f7ea2e9..dfd53847 100644
--- a/tests/expectations/tests/bitfield-32bit-overflow.rs
+++ b/tests/expectations/tests/bitfield-32bit-overflow.rs
@@ -4,11 +4,10 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[repr(C, packed)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct MuchBitfield {
pub _bitfield_1: [u8; 5usize],
- pub __bindgen_align: [u8; 0usize],
}
#[test]
fn bindgen_test_layout_MuchBitfield() {
@@ -23,11 +22,6 @@ fn bindgen_test_layout_MuchBitfield() {
concat!("Alignment of ", stringify!(MuchBitfield))
);
}
-impl Clone for MuchBitfield {
- fn clone(&self) -> Self {
- *self
- }
-}
impl MuchBitfield {
#[inline]
pub fn m0(&self) -> ::std::os::raw::c_char {
@@ -39,13 +33,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 1u64 as u64;
+ let mask = 0x1 as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m0(&mut self, val: ::std::os::raw::c_char) {
- let mask = 1u64 as u64;
+ let mask = 0x1 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -75,13 +69,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 2u64 as u64;
+ let mask = 0x2 as u64;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m1(&mut self, val: ::std::os::raw::c_char) {
- let mask = 2u64 as u64;
+ let mask = 0x2 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -111,13 +105,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 4u64 as u64;
+ let mask = 0x4 as u64;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m2(&mut self, val: ::std::os::raw::c_char) {
- let mask = 4u64 as u64;
+ let mask = 0x4 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -147,13 +141,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 8u64 as u64;
+ let mask = 0x8 as u64;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m3(&mut self, val: ::std::os::raw::c_char) {
- let mask = 8u64 as u64;
+ let mask = 0x8 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -183,13 +177,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 16u64 as u64;
+ let mask = 0x10 as u64;
let val = (unit_field_val & mask) >> 4usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m4(&mut self, val: ::std::os::raw::c_char) {
- let mask = 16u64 as u64;
+ let mask = 0x10 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -219,13 +213,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 32u64 as u64;
+ let mask = 0x20 as u64;
let val = (unit_field_val & mask) >> 5usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m5(&mut self, val: ::std::os::raw::c_char) {
- let mask = 32u64 as u64;
+ let mask = 0x20 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -255,13 +249,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 64u64 as u64;
+ let mask = 0x40 as u64;
let val = (unit_field_val & mask) >> 6usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m6(&mut self, val: ::std::os::raw::c_char) {
- let mask = 64u64 as u64;
+ let mask = 0x40 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -291,13 +285,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 128u64 as u64;
+ let mask = 0x80 as u64;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m7(&mut self, val: ::std::os::raw::c_char) {
- let mask = 128u64 as u64;
+ let mask = 0x80 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -327,13 +321,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 256u64 as u64;
+ let mask = 0x100 as u64;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m8(&mut self, val: ::std::os::raw::c_char) {
- let mask = 256u64 as u64;
+ let mask = 0x100 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -363,13 +357,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 512u64 as u64;
+ let mask = 0x200 as u64;
let val = (unit_field_val & mask) >> 9usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m9(&mut self, val: ::std::os::raw::c_char) {
- let mask = 512u64 as u64;
+ let mask = 0x200 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -399,13 +393,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 1024u64 as u64;
+ let mask = 0x400 as u64;
let val = (unit_field_val & mask) >> 10usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m10(&mut self, val: ::std::os::raw::c_char) {
- let mask = 1024u64 as u64;
+ let mask = 0x400 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -435,13 +429,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 2048u64 as u64;
+ let mask = 0x800 as u64;
let val = (unit_field_val & mask) >> 11usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m11(&mut self, val: ::std::os::raw::c_char) {
- let mask = 2048u64 as u64;
+ let mask = 0x800 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -471,13 +465,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 4096u64 as u64;
+ let mask = 0x1000 as u64;
let val = (unit_field_val & mask) >> 12usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m12(&mut self, val: ::std::os::raw::c_char) {
- let mask = 4096u64 as u64;
+ let mask = 0x1000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -507,13 +501,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 8192u64 as u64;
+ let mask = 0x2000 as u64;
let val = (unit_field_val & mask) >> 13usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m13(&mut self, val: ::std::os::raw::c_char) {
- let mask = 8192u64 as u64;
+ let mask = 0x2000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -543,13 +537,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 16384u64 as u64;
+ let mask = 0x4000 as u64;
let val = (unit_field_val & mask) >> 14usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m14(&mut self, val: ::std::os::raw::c_char) {
- let mask = 16384u64 as u64;
+ let mask = 0x4000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -579,13 +573,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 32768u64 as u64;
+ let mask = 0x8000 as u64;
let val = (unit_field_val & mask) >> 15usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m15(&mut self, val: ::std::os::raw::c_char) {
- let mask = 32768u64 as u64;
+ let mask = 0x8000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -615,13 +609,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 65536u64 as u64;
+ let mask = 0x10000 as u64;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m16(&mut self, val: ::std::os::raw::c_char) {
- let mask = 65536u64 as u64;
+ let mask = 0x10000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -651,13 +645,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 131072u64 as u64;
+ let mask = 0x20000 as u64;
let val = (unit_field_val & mask) >> 17usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m17(&mut self, val: ::std::os::raw::c_char) {
- let mask = 131072u64 as u64;
+ let mask = 0x20000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -687,13 +681,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 262144u64 as u64;
+ let mask = 0x40000 as u64;
let val = (unit_field_val & mask) >> 18usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m18(&mut self, val: ::std::os::raw::c_char) {
- let mask = 262144u64 as u64;
+ let mask = 0x40000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -723,13 +717,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 524288u64 as u64;
+ let mask = 0x80000 as u64;
let val = (unit_field_val & mask) >> 19usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m19(&mut self, val: ::std::os::raw::c_char) {
- let mask = 524288u64 as u64;
+ let mask = 0x80000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -759,13 +753,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 1048576u64 as u64;
+ let mask = 0x100000 as u64;
let val = (unit_field_val & mask) >> 20usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m20(&mut self, val: ::std::os::raw::c_char) {
- let mask = 1048576u64 as u64;
+ let mask = 0x100000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -795,13 +789,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 2097152u64 as u64;
+ let mask = 0x200000 as u64;
let val = (unit_field_val & mask) >> 21usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m21(&mut self, val: ::std::os::raw::c_char) {
- let mask = 2097152u64 as u64;
+ let mask = 0x200000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -831,13 +825,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 4194304u64 as u64;
+ let mask = 0x400000 as u64;
let val = (unit_field_val & mask) >> 22usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m22(&mut self, val: ::std::os::raw::c_char) {
- let mask = 4194304u64 as u64;
+ let mask = 0x400000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -867,13 +861,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 8388608u64 as u64;
+ let mask = 0x800000 as u64;
let val = (unit_field_val & mask) >> 23usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m23(&mut self, val: ::std::os::raw::c_char) {
- let mask = 8388608u64 as u64;
+ let mask = 0x800000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -903,13 +897,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 16777216u64 as u64;
+ let mask = 0x1000000 as u64;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m24(&mut self, val: ::std::os::raw::c_char) {
- let mask = 16777216u64 as u64;
+ let mask = 0x1000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -939,13 +933,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 33554432u64 as u64;
+ let mask = 0x2000000 as u64;
let val = (unit_field_val & mask) >> 25usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m25(&mut self, val: ::std::os::raw::c_char) {
- let mask = 33554432u64 as u64;
+ let mask = 0x2000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -975,13 +969,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 67108864u64 as u64;
+ let mask = 0x4000000 as u64;
let val = (unit_field_val & mask) >> 26usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m26(&mut self, val: ::std::os::raw::c_char) {
- let mask = 67108864u64 as u64;
+ let mask = 0x4000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1011,13 +1005,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 134217728u64 as u64;
+ let mask = 0x8000000 as u64;
let val = (unit_field_val & mask) >> 27usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m27(&mut self, val: ::std::os::raw::c_char) {
- let mask = 134217728u64 as u64;
+ let mask = 0x8000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1047,13 +1041,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 268435456u64 as u64;
+ let mask = 0x10000000 as u64;
let val = (unit_field_val & mask) >> 28usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m28(&mut self, val: ::std::os::raw::c_char) {
- let mask = 268435456u64 as u64;
+ let mask = 0x10000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1083,13 +1077,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 536870912u64 as u64;
+ let mask = 0x20000000 as u64;
let val = (unit_field_val & mask) >> 29usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m29(&mut self, val: ::std::os::raw::c_char) {
- let mask = 536870912u64 as u64;
+ let mask = 0x20000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1119,13 +1113,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 1073741824u64 as u64;
+ let mask = 0x40000000 as u64;
let val = (unit_field_val & mask) >> 30usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m30(&mut self, val: ::std::os::raw::c_char) {
- let mask = 1073741824u64 as u64;
+ let mask = 0x40000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1155,13 +1149,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 2147483648u64 as u64;
+ let mask = 0x80000000 as u64;
let val = (unit_field_val & mask) >> 31usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m31(&mut self, val: ::std::os::raw::c_char) {
- let mask = 2147483648u64 as u64;
+ let mask = 0x80000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1191,13 +1185,13 @@ impl MuchBitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 4294967296u64 as u64;
+ let mask = 0x100000000 as u64;
let val = (unit_field_val & mask) >> 32usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_m32(&mut self, val: ::std::os::raw::c_char) {
- let mask = 4294967296u64 as u64;
+ let mask = 0x100000000 as u64;
let val = val as u8 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1253,38 +1247,38 @@ impl MuchBitfield {
m31: ::std::os::raw::c_char,
m32: ::std::os::raw::c_char,
) -> u64 {
- (((((((((((((((((((((((((((((((((0 | ((m0 as u8 as u64) << 0usize) & (1u64 as u64)) |
- ((m1 as u8 as u64) << 1usize) & (2u64 as u64)) |
- ((m2 as u8 as u64) << 2usize) & (4u64 as u64)) |
- ((m3 as u8 as u64) << 3usize) & (8u64 as u64)) |
- ((m4 as u8 as u64) << 4usize) & (16u64 as u64)) |
- ((m5 as u8 as u64) << 5usize) & (32u64 as u64)) |
- ((m6 as u8 as u64) << 6usize) & (64u64 as u64)) |
- ((m7 as u8 as u64) << 7usize) & (128u64 as u64)) |
- ((m8 as u8 as u64) << 8usize) & (256u64 as u64)) |
- ((m9 as u8 as u64) << 9usize) & (512u64 as u64)) |
- ((m10 as u8 as u64) << 10usize) & (1024u64 as u64)) |
- ((m11 as u8 as u64) << 11usize) & (2048u64 as u64)) |
- ((m12 as u8 as u64) << 12usize) & (4096u64 as u64)) |
- ((m13 as u8 as u64) << 13usize) & (8192u64 as u64)) |
- ((m14 as u8 as u64) << 14usize) & (16384u64 as u64)) |
- ((m15 as u8 as u64) << 15usize) & (32768u64 as u64)) |
- ((m16 as u8 as u64) << 16usize) & (65536u64 as u64)) |
- ((m17 as u8 as u64) << 17usize) & (131072u64 as u64)) |
- ((m18 as u8 as u64) << 18usize) & (262144u64 as u64)) |
- ((m19 as u8 as u64) << 19usize) & (524288u64 as u64)) |
- ((m20 as u8 as u64) << 20usize) & (1048576u64 as u64)) |
- ((m21 as u8 as u64) << 21usize) & (2097152u64 as u64)) |
- ((m22 as u8 as u64) << 22usize) & (4194304u64 as u64)) |
- ((m23 as u8 as u64) << 23usize) & (8388608u64 as u64)) |
- ((m24 as u8 as u64) << 24usize) & (16777216u64 as u64)) |
- ((m25 as u8 as u64) << 25usize) & (33554432u64 as u64)) |
- ((m26 as u8 as u64) << 26usize) & (67108864u64 as u64)) |
- ((m27 as u8 as u64) << 27usize) & (134217728u64 as u64)) |
- ((m28 as u8 as u64) << 28usize) & (268435456u64 as u64)) |
- ((m29 as u8 as u64) << 29usize) & (536870912u64 as u64)) |
- ((m30 as u8 as u64) << 30usize) & (1073741824u64 as u64)) |
- ((m31 as u8 as u64) << 31usize) & (2147483648u64 as u64)) |
- ((m32 as u8 as u64) << 32usize) & (4294967296u64 as u64))
+ (((((((((((((((((((((((((((((((((0 | ((m0 as u8 as u64) << 0usize) & (0x1 as u64))
+ | ((m1 as u8 as u64) << 1usize) & (0x2 as u64))
+ | ((m2 as u8 as u64) << 2usize) & (0x4 as u64))
+ | ((m3 as u8 as u64) << 3usize) & (0x8 as u64))
+ | ((m4 as u8 as u64) << 4usize) & (0x10 as u64))
+ | ((m5 as u8 as u64) << 5usize) & (0x20 as u64))
+ | ((m6 as u8 as u64) << 6usize) & (0x40 as u64))
+ | ((m7 as u8 as u64) << 7usize) & (0x80 as u64))
+ | ((m8 as u8 as u64) << 8usize) & (0x100 as u64))
+ | ((m9 as u8 as u64) << 9usize) & (0x200 as u64))
+ | ((m10 as u8 as u64) << 10usize) & (0x400 as u64))
+ | ((m11 as u8 as u64) << 11usize) & (0x800 as u64))
+ | ((m12 as u8 as u64) << 12usize) & (0x1000 as u64))
+ | ((m13 as u8 as u64) << 13usize) & (0x2000 as u64))
+ | ((m14 as u8 as u64) << 14usize) & (0x4000 as u64))
+ | ((m15 as u8 as u64) << 15usize) & (0x8000 as u64))
+ | ((m16 as u8 as u64) << 16usize) & (0x10000 as u64))
+ | ((m17 as u8 as u64) << 17usize) & (0x20000 as u64))
+ | ((m18 as u8 as u64) << 18usize) & (0x40000 as u64))
+ | ((m19 as u8 as u64) << 19usize) & (0x80000 as u64))
+ | ((m20 as u8 as u64) << 20usize) & (0x100000 as u64))
+ | ((m21 as u8 as u64) << 21usize) & (0x200000 as u64))
+ | ((m22 as u8 as u64) << 22usize) & (0x400000 as u64))
+ | ((m23 as u8 as u64) << 23usize) & (0x800000 as u64))
+ | ((m24 as u8 as u64) << 24usize) & (0x1000000 as u64))
+ | ((m25 as u8 as u64) << 25usize) & (0x2000000 as u64))
+ | ((m26 as u8 as u64) << 26usize) & (0x4000000 as u64))
+ | ((m27 as u8 as u64) << 27usize) & (0x8000000 as u64))
+ | ((m28 as u8 as u64) << 28usize) & (0x10000000 as u64))
+ | ((m29 as u8 as u64) << 29usize) & (0x20000000 as u64))
+ | ((m30 as u8 as u64) << 30usize) & (0x40000000 as u64))
+ | ((m31 as u8 as u64) << 31usize) & (0x80000000 as u64))
+ | ((m32 as u8 as u64) << 32usize) & (0x100000000 as u64))
}
}
diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs
index ebb3fef4..84362d12 100644
--- a/tests/expectations/tests/bitfield-enum-basic.rs
+++ b/tests/expectations/tests/bitfield-enum-basic.rs
@@ -9,28 +9,30 @@ pub const Foo_Baz: Foo = Foo(4);
pub const Foo_Duplicated: Foo = Foo(4);
pub const Foo_Negative: Foo = Foo(-3);
impl ::std::ops::BitOr<Foo> for Foo {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
- fn bitor(self, other: Self) -> Self { Foo(self.0 | other.0) }
+ fn bitor(self, other: Self) -> Self {
+ Foo(self.0 | other.0)
+ }
}
impl ::std::ops::BitOrAssign for Foo {
#[inline]
- fn bitor_assign(&mut self, rhs: Foo) { self.0 |= rhs.0; }
+ fn bitor_assign(&mut self, rhs: Foo) {
+ self.0 |= rhs.0;
+ }
}
impl ::std::ops::BitAnd<Foo> for Foo {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
- fn bitand(self, other: Self) -> Self { Foo(self.0 & other.0) }
+ fn bitand(self, other: Self) -> Self {
+ Foo(self.0 & other.0)
+ }
}
impl ::std::ops::BitAndAssign for Foo {
#[inline]
- fn bitand_assign(&mut self, rhs: Foo) { self.0 &= rhs.0; }
+ fn bitand_assign(&mut self, rhs: Foo) {
+ self.0 &= rhs.0;
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -40,28 +42,30 @@ pub const Buz_Baz: Buz = Buz(4);
pub const Buz_Duplicated: Buz = Buz(4);
pub const Buz_Negative: Buz = Buz(-3);
impl ::std::ops::BitOr<Buz> for Buz {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
- fn bitor(self, other: Self) -> Self { Buz(self.0 | other.0) }
+ fn bitor(self, other: Self) -> Self {
+ Buz(self.0 | other.0)
+ }
}
impl ::std::ops::BitOrAssign for Buz {
#[inline]
- fn bitor_assign(&mut self, rhs: Buz) { self.0 |= rhs.0; }
+ fn bitor_assign(&mut self, rhs: Buz) {
+ self.0 |= rhs.0;
+ }
}
impl ::std::ops::BitAnd<Buz> for Buz {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
- fn bitand(self, other: Self) -> Self { Buz(self.0 & other.0) }
+ fn bitand(self, other: Self) -> Self {
+ Buz(self.0 & other.0)
+ }
}
impl ::std::ops::BitAndAssign for Buz {
#[inline]
- fn bitand_assign(&mut self, rhs: Buz) { self.0 &= rhs.0; }
+ fn bitand_assign(&mut self, rhs: Buz) {
+ self.0 &= rhs.0;
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -69,44 +73,43 @@ pub struct Buz(pub ::std::os::raw::c_schar);
pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2);
impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
- fn bitor(self, other: Self) -> Self { _bindgen_ty_1(self.0 | other.0) }
+ fn bitor(self, other: Self) -> Self {
+ _bindgen_ty_1(self.0 | other.0)
+ }
}
impl ::std::ops::BitOrAssign for _bindgen_ty_1 {
#[inline]
- fn bitor_assign(&mut self, rhs: _bindgen_ty_1) { self.0 |= rhs.0; }
+ fn bitor_assign(&mut self, rhs: _bindgen_ty_1) {
+ self.0 |= rhs.0;
+ }
}
impl ::std::ops::BitAnd<_bindgen_ty_1> for _bindgen_ty_1 {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
- fn bitand(self, other: Self) -> Self { _bindgen_ty_1(self.0 & other.0) }
+ fn bitand(self, other: Self) -> Self {
+ _bindgen_ty_1(self.0 & other.0)
+ }
}
impl ::std::ops::BitAndAssign for _bindgen_ty_1 {
#[inline]
- fn bitand_assign(&mut self, rhs: _bindgen_ty_1) { self.0 &= rhs.0; }
+ fn bitand_assign(&mut self, rhs: _bindgen_ty_1) {
+ self.0 &= rhs.0;
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint);
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Dummy {
pub _address: u8,
}
pub const Dummy_DUMMY_FOO: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(1);
pub const Dummy_DUMMY_BAR: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(2);
impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
fn bitor(self, other: Self) -> Self {
Dummy__bindgen_ty_1(self.0 | other.0)
@@ -114,13 +117,12 @@ impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
}
impl ::std::ops::BitOrAssign for Dummy__bindgen_ty_1 {
#[inline]
- fn bitor_assign(&mut self, rhs: Dummy__bindgen_ty_1) { self.0 |= rhs.0; }
+ fn bitor_assign(&mut self, rhs: Dummy__bindgen_ty_1) {
+ self.0 |= rhs.0;
+ }
}
impl ::std::ops::BitAnd<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
- type
- Output
- =
- Self;
+ type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self {
Dummy__bindgen_ty_1(self.0 & other.0)
@@ -128,18 +130,23 @@ impl ::std::ops::BitAnd<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
}
impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 {
#[inline]
- fn bitand_assign(&mut self, rhs: Dummy__bindgen_ty_1) { self.0 &= rhs.0; }
+ fn bitand_assign(&mut self, rhs: Dummy__bindgen_ty_1) {
+ self.0 &= rhs.0;
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint);
#[test]
fn bindgen_test_layout_Dummy() {
- assert_eq!(::std::mem::size_of::<Dummy>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Dummy ) ));
- assert_eq! (::std::mem::align_of::<Dummy>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Dummy ) ));
-}
-impl Clone for Dummy {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Dummy>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Dummy))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Dummy>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Dummy))
+ );
}
diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs
index 5606f64e..c3209ea5 100644
--- a/tests/expectations/tests/bitfield-large.rs
+++ b/tests/expectations/tests/bitfield-large.rs
@@ -5,28 +5,28 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct HasBigBitfield {
pub _bitfield_1: [u8; 16usize],
}
#[test]
fn bindgen_test_layout_HasBigBitfield() {
- assert_eq!(::std::mem::size_of::<HasBigBitfield>() , 16usize , concat ! (
- "Size of: " , stringify ! ( HasBigBitfield ) ));
-}
-impl Clone for HasBigBitfield {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<HasBigBitfield>(),
+ 16usize,
+ concat!("Size of: ", stringify!(HasBigBitfield))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct HasTwoBigBitfields {
pub _bitfield_1: [u8; 16usize],
}
#[test]
fn bindgen_test_layout_HasTwoBigBitfields() {
- assert_eq!(::std::mem::size_of::<HasTwoBigBitfields>() , 16usize , concat
- ! ( "Size of: " , stringify ! ( HasTwoBigBitfields ) ));
-}
-impl Clone for HasTwoBigBitfields {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<HasTwoBigBitfields>(),
+ 16usize,
+ concat!("Size of: ", stringify!(HasTwoBigBitfields))
+ );
}
diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs
index be55ce38..d202893f 100644
--- a/tests/expectations/tests/bitfield-method-same-name.rs
+++ b/tests/expectations/tests/bitfield-method-same-name.rs
@@ -4,11 +4,10 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[repr(C, packed)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _bitfield_1: u8,
- pub __bindgen_align: [u8; 0usize],
}
#[test]
fn bindgen_test_layout_Foo() {
@@ -24,22 +23,17 @@ fn bindgen_test_layout_Foo() {
);
}
extern "C" {
- #[link_name = "_ZN3Foo4typeEv"]
+ #[link_name = "\u{1}_ZN3Foo4typeEv"]
pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char;
}
extern "C" {
- #[link_name = "_ZN3Foo9set_type_Ec"]
+ #[link_name = "\u{1}_ZN3Foo9set_type_Ec"]
pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char);
}
extern "C" {
- #[link_name = "_ZN3Foo8set_typeEc"]
+ #[link_name = "\u{1}_ZN3Foo8set_typeEc"]
pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char);
}
-impl Clone for Foo {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Foo {
#[inline]
pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char {
@@ -51,13 +45,13 @@ impl Foo {
::std::mem::size_of::<u8>(),
)
};
- let mask = 7u64 as u8;
+ let mask = 0x7 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) {
- let mask = 7u64 as u8;
+ let mask = 0x7 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -79,7 +73,7 @@ impl Foo {
}
#[inline]
pub fn new_bitfield_1(type__bindgen_bitfield: ::std::os::raw::c_char) -> u8 {
- (0 | ((type__bindgen_bitfield as u8 as u8) << 0usize) & (7u64 as u8))
+ (0 | ((type__bindgen_bitfield as u8 as u8) << 0usize) & (0x7 as u8))
}
#[inline]
pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char {
diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs
index 6479bb50..aa718a74 100644
--- a/tests/expectations/tests/bitfield_align.rs
+++ b/tests/expectations/tests/bitfield_align.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub x: ::std::os::raw::c_uchar,
pub _bitfield_1: [u8; 2usize],
@@ -35,11 +35,6 @@ fn bindgen_test_layout_A() {
concat!("Alignment of field: ", stringify!(A), "::", stringify!(y))
);
}
-impl Clone for A {
- fn clone(&self) -> Self {
- *self
- }
-}
impl A {
#[inline]
pub fn b1(&self) -> ::std::os::raw::c_uint {
@@ -51,13 +46,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 1u64 as u16;
+ let mask = 0x1 as u16;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 1u64 as u16;
+ let mask = 0x1 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -87,13 +82,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 2u64 as u16;
+ let mask = 0x2 as u16;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 2u64 as u16;
+ let mask = 0x2 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -123,13 +118,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 4u64 as u16;
+ let mask = 0x4 as u16;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b3(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 4u64 as u16;
+ let mask = 0x4 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -159,13 +154,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 8u64 as u16;
+ let mask = 0x8 as u16;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b4(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 8u64 as u16;
+ let mask = 0x8 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -195,13 +190,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 16u64 as u16;
+ let mask = 0x10 as u16;
let val = (unit_field_val & mask) >> 4usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b5(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 16u64 as u16;
+ let mask = 0x10 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -231,13 +226,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 32u64 as u16;
+ let mask = 0x20 as u16;
let val = (unit_field_val & mask) >> 5usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b6(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 32u64 as u16;
+ let mask = 0x20 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -267,13 +262,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = (unit_field_val & mask) >> 6usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b7(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -303,13 +298,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b8(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -339,13 +334,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b9(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -375,13 +370,13 @@ impl A {
::std::mem::size_of::<u16>(),
)
};
- let mask = 512u64 as u16;
+ let mask = 0x200 as u16;
let val = (unit_field_val & mask) >> 9usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b10(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 512u64 as u16;
+ let mask = 0x200 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -414,20 +409,20 @@ impl A {
b9: ::std::os::raw::c_uint,
b10: ::std::os::raw::c_uint,
) -> u16 {
- ((((((((((0 | ((b1 as u32 as u16) << 0usize) & (1u64 as u16)) |
- ((b2 as u32 as u16) << 1usize) & (2u64 as u16)) |
- ((b3 as u32 as u16) << 2usize) & (4u64 as u16)) |
- ((b4 as u32 as u16) << 3usize) & (8u64 as u16)) |
- ((b5 as u32 as u16) << 4usize) & (16u64 as u16)) |
- ((b6 as u32 as u16) << 5usize) & (32u64 as u16)) |
- ((b7 as u32 as u16) << 6usize) & (64u64 as u16)) |
- ((b8 as u32 as u16) << 7usize) & (128u64 as u16)) |
- ((b9 as u32 as u16) << 8usize) & (256u64 as u16)) |
- ((b10 as u32 as u16) << 9usize) & (512u64 as u16))
+ ((((((((((0 | ((b1 as u32 as u16) << 0usize) & (0x1 as u16))
+ | ((b2 as u32 as u16) << 1usize) & (0x2 as u16))
+ | ((b3 as u32 as u16) << 2usize) & (0x4 as u16))
+ | ((b4 as u32 as u16) << 3usize) & (0x8 as u16))
+ | ((b5 as u32 as u16) << 4usize) & (0x10 as u16))
+ | ((b6 as u32 as u16) << 5usize) & (0x20 as u16))
+ | ((b7 as u32 as u16) << 6usize) & (0x40 as u16))
+ | ((b8 as u32 as u16) << 7usize) & (0x80 as u16))
+ | ((b9 as u32 as u16) << 8usize) & (0x100 as u16))
+ | ((b10 as u32 as u16) << 9usize) & (0x200 as u16))
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct B {
pub _bitfield_1: u32,
pub __bindgen_align: [u32; 0usize],
@@ -445,11 +440,6 @@ fn bindgen_test_layout_B() {
concat!("Alignment of ", stringify!(B))
);
}
-impl Clone for B {
- fn clone(&self) -> Self {
- *self
- }
-}
impl B {
#[inline]
pub fn foo(&self) -> ::std::os::raw::c_uint {
@@ -461,13 +451,13 @@ impl B {
::std::mem::size_of::<u32>(),
)
};
- let mask = 2147483647u64 as u32;
+ let mask = 0x7fffffff as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 2147483647u64 as u32;
+ let mask = 0x7fffffff as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -497,13 +487,13 @@ impl B {
::std::mem::size_of::<u32>(),
)
};
- let mask = 2147483648u64 as u32;
+ let mask = 0x80000000 as u32;
let val = (unit_field_val & mask) >> 31usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) {
- let mask = 2147483648u64 as u32;
+ let mask = 0x80000000 as u32;
let val = val as u8 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -525,12 +515,12 @@ impl B {
}
#[inline]
pub fn new_bitfield_1(foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar) -> u32 {
- ((0 | ((foo as u32 as u32) << 0usize) & (2147483647u64 as u32)) |
- ((bar as u8 as u32) << 31usize) & (2147483648u64 as u32))
+ ((0 | ((foo as u32 as u32) << 0usize) & (0x7fffffff as u32))
+ | ((bar as u8 as u32) << 31usize) & (0x80000000 as u32))
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct C {
pub x: ::std::os::raw::c_uchar,
pub _bitfield_1: u8,
@@ -559,11 +549,6 @@ fn bindgen_test_layout_C() {
concat!("Alignment of field: ", stringify!(C), "::", stringify!(baz))
);
}
-impl Clone for C {
- fn clone(&self) -> Self {
- *self
- }
-}
impl C {
#[inline]
pub fn b1(&self) -> ::std::os::raw::c_uint {
@@ -575,13 +560,13 @@ impl C {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u32 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -611,13 +596,13 @@ impl C {
::std::mem::size_of::<u8>(),
)
};
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = val as u32 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -639,12 +624,12 @@ impl C {
}
#[inline]
pub fn new_bitfield_1(b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint) -> u8 {
- ((0 | ((b1 as u32 as u8) << 0usize) & (1u64 as u8)) |
- ((b2 as u32 as u8) << 1usize) & (2u64 as u8))
+ ((0 | ((b1 as u32 as u8) << 0usize) & (0x1 as u8))
+ | ((b2 as u32 as u8) << 1usize) & (0x2 as u8))
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Date1 {
pub _bitfield_1: [u8; 3usize],
pub __bindgen_padding_0: u8,
@@ -663,11 +648,6 @@ fn bindgen_test_layout_Date1() {
concat!("Alignment of ", stringify!(Date1))
);
}
-impl Clone for Date1 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Date1 {
#[inline]
pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort {
@@ -679,13 +659,13 @@ impl Date1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 7u64 as u32;
+ let mask = 0x7 as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 7u64 as u32;
+ let mask = 0x7 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -715,13 +695,13 @@ impl Date1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 504u64 as u32;
+ let mask = 0x1f8 as u32;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 504u64 as u32;
+ let mask = 0x1f8 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -751,13 +731,13 @@ impl Date1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15872u64 as u32;
+ let mask = 0x3e00 as u32;
let val = (unit_field_val & mask) >> 9usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 15872u64 as u32;
+ let mask = 0x3e00 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -787,13 +767,13 @@ impl Date1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 16711680u64 as u32;
+ let mask = 0xff0000 as u32;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 16711680u64 as u32;
+ let mask = 0xff0000 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -820,14 +800,14 @@ impl Date1 {
nMonth: ::std::os::raw::c_ushort,
nYear: ::std::os::raw::c_ushort,
) -> u32 {
- ((((0 | ((nWeekDay as u16 as u32) << 0usize) & (7u64 as u32)) |
- ((nMonthDay as u16 as u32) << 3usize) & (504u64 as u32)) |
- ((nMonth as u16 as u32) << 9usize) & (15872u64 as u32)) |
- ((nYear as u16 as u32) << 16usize) & (16711680u64 as u32))
+ ((((0 | ((nWeekDay as u16 as u32) << 0usize) & (0x7 as u32))
+ | ((nMonthDay as u16 as u32) << 3usize) & (0x1f8 as u32))
+ | ((nMonth as u16 as u32) << 9usize) & (0x3e00 as u32))
+ | ((nYear as u16 as u32) << 16usize) & (0xff0000 as u32))
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Date2 {
pub _bitfield_1: [u8; 4usize],
pub __bindgen_align: [u16; 0usize],
@@ -845,11 +825,6 @@ fn bindgen_test_layout_Date2() {
concat!("Alignment of ", stringify!(Date2))
);
}
-impl Clone for Date2 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Date2 {
#[inline]
pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort {
@@ -861,13 +836,13 @@ impl Date2 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 7u64 as u32;
+ let mask = 0x7 as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 7u64 as u32;
+ let mask = 0x7 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -897,13 +872,13 @@ impl Date2 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 504u64 as u32;
+ let mask = 0x1f8 as u32;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 504u64 as u32;
+ let mask = 0x1f8 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -933,13 +908,13 @@ impl Date2 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15872u64 as u32;
+ let mask = 0x3e00 as u32;
let val = (unit_field_val & mask) >> 9usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 15872u64 as u32;
+ let mask = 0x3e00 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -969,13 +944,13 @@ impl Date2 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 16711680u64 as u32;
+ let mask = 0xff0000 as u32;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 16711680u64 as u32;
+ let mask = 0xff0000 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1005,13 +980,13 @@ impl Date2 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 4278190080u64 as u32;
+ let mask = 0xff000000 as u32;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_byte(&mut self, val: ::std::os::raw::c_uchar) {
- let mask = 4278190080u64 as u32;
+ let mask = 0xff000000 as u32;
let val = val as u8 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1039,15 +1014,15 @@ impl Date2 {
nYear: ::std::os::raw::c_ushort,
byte: ::std::os::raw::c_uchar,
) -> u32 {
- (((((0 | ((nWeekDay as u16 as u32) << 0usize) & (7u64 as u32)) |
- ((nMonthDay as u16 as u32) << 3usize) & (504u64 as u32)) |
- ((nMonth as u16 as u32) << 9usize) & (15872u64 as u32)) |
- ((nYear as u16 as u32) << 16usize) & (16711680u64 as u32)) |
- ((byte as u8 as u32) << 24usize) & (4278190080u64 as u32))
+ (((((0 | ((nWeekDay as u16 as u32) << 0usize) & (0x7 as u32))
+ | ((nMonthDay as u16 as u32) << 3usize) & (0x1f8 as u32))
+ | ((nMonth as u16 as u32) << 9usize) & (0x3e00 as u32))
+ | ((nYear as u16 as u32) << 16usize) & (0xff0000 as u32))
+ | ((byte as u8 as u32) << 24usize) & (0xff000000 as u32))
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Date3 {
pub _bitfield_1: [u8; 3usize],
pub byte: ::std::os::raw::c_uchar,
@@ -1076,11 +1051,6 @@ fn bindgen_test_layout_Date3() {
)
);
}
-impl Clone for Date3 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Date3 {
#[inline]
pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort {
@@ -1092,13 +1062,13 @@ impl Date3 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 7u64 as u32;
+ let mask = 0x7 as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 7u64 as u32;
+ let mask = 0x7 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1128,13 +1098,13 @@ impl Date3 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 504u64 as u32;
+ let mask = 0x1f8 as u32;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 504u64 as u32;
+ let mask = 0x1f8 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1164,13 +1134,13 @@ impl Date3 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15872u64 as u32;
+ let mask = 0x3e00 as u32;
let val = (unit_field_val & mask) >> 9usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 15872u64 as u32;
+ let mask = 0x3e00 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1200,13 +1170,13 @@ impl Date3 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 16711680u64 as u32;
+ let mask = 0xff0000 as u32;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 16711680u64 as u32;
+ let mask = 0xff0000 as u32;
let val = val as u16 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1233,9 +1203,9 @@ impl Date3 {
nMonth: ::std::os::raw::c_ushort,
nYear: ::std::os::raw::c_ushort,
) -> u32 {
- ((((0 | ((nWeekDay as u16 as u32) << 0usize) & (7u64 as u32)) |
- ((nMonthDay as u16 as u32) << 3usize) & (504u64 as u32)) |
- ((nMonth as u16 as u32) << 9usize) & (15872u64 as u32)) |
- ((nYear as u16 as u32) << 16usize) & (16711680u64 as u32))
+ ((((0 | ((nWeekDay as u16 as u32) << 0usize) & (0x7 as u32))
+ | ((nMonthDay as u16 as u32) << 3usize) & (0x1f8 as u32))
+ | ((nMonth as u16 as u32) << 9usize) & (0x3e00 as u32))
+ | ((nYear as u16 as u32) << 16usize) & (0xff0000 as u32))
}
}
diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs
index d3ce64f8..b10e126f 100644
--- a/tests/expectations/tests/bitfield_align_2.rs
+++ b/tests/expectations/tests/bitfield_align_2.rs
@@ -13,7 +13,7 @@ pub enum MyEnum {
FOUR = 3,
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct TaggedPtr {
pub _bitfield_1: u64,
pub __bindgen_align: [u64; 0usize],
@@ -31,11 +31,6 @@ fn bindgen_test_layout_TaggedPtr() {
concat!("Alignment of ", stringify!(TaggedPtr))
);
}
-impl Clone for TaggedPtr {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for TaggedPtr {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -52,13 +47,13 @@ impl TaggedPtr {
::std::mem::size_of::<u64>(),
)
};
- let mask = 3u64 as u64;
+ let mask = 0x3 as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_tag(&mut self, val: MyEnum) {
- let mask = 3u64 as u64;
+ let mask = 0x3 as u64;
let val = val as u32 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -88,13 +83,13 @@ impl TaggedPtr {
::std::mem::size_of::<u64>(),
)
};
- let mask = 18446744073709551612u64 as u64;
+ let mask = 0xfffffffffffffffc as u64;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_ptr(&mut self, val: ::std::os::raw::c_long) {
- let mask = 18446744073709551612u64 as u64;
+ let mask = 0xfffffffffffffffc as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -116,7 +111,7 @@ impl TaggedPtr {
}
#[inline]
pub fn new_bitfield_1(tag: MyEnum, ptr: ::std::os::raw::c_long) -> u64 {
- ((0 | ((tag as u32 as u64) << 0usize) & (3u64 as u64)) |
- ((ptr as u64 as u64) << 2usize) & (18446744073709551612u64 as u64))
+ ((0 | ((tag as u32 as u64) << 0usize) & (0x3 as u64))
+ | ((ptr as u64 as u64) << 2usize) & (0xfffffffffffffffc as u64))
}
}
diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/tests/expectations/tests/bitfield_large_overflow.rs
new file mode 100644
index 00000000..e5b254cf
--- /dev/null
+++ b/tests/expectations/tests/bitfield_large_overflow.rs
@@ -0,0 +1,28 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+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))
+ );
+}
+extern "C" {
+ #[link_name = "\u{1}a"]
+ pub static mut a: _bindgen_ty_1;
+}
diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs
index 736d6360..32e61e67 100644
--- a/tests/expectations/tests/bitfield_method_mangling.rs
+++ b/tests/expectations/tests/bitfield_method_mangling.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct mach_msg_type_descriptor_t {
pub _bitfield_1: u32,
pub __bindgen_align: [u32; 0usize],
@@ -23,11 +23,6 @@ fn bindgen_test_layout_mach_msg_type_descriptor_t() {
concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t))
);
}
-impl Clone for mach_msg_type_descriptor_t {
- fn clone(&self) -> Self {
- *self
- }
-}
impl mach_msg_type_descriptor_t {
#[inline]
pub fn pad3(&self) -> ::std::os::raw::c_uint {
@@ -39,13 +34,13 @@ impl mach_msg_type_descriptor_t {
::std::mem::size_of::<u32>(),
)
};
- let mask = 16777215u64 as u32;
+ let mask = 0xffffff as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_pad3(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 16777215u64 as u32;
+ let mask = 0xffffff as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -75,13 +70,13 @@ impl mach_msg_type_descriptor_t {
::std::mem::size_of::<u32>(),
)
};
- let mask = 4278190080u64 as u32;
+ let mask = 0xff000000 as u32;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_type(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 4278190080u64 as u32;
+ let mask = 0xff000000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -103,7 +98,7 @@ impl mach_msg_type_descriptor_t {
}
#[inline]
pub fn new_bitfield_1(pad3: ::std::os::raw::c_uint, type_: ::std::os::raw::c_uint) -> u32 {
- ((0 | ((pad3 as u32 as u32) << 0usize) & (16777215u64 as u32)) |
- ((type_ as u32 as u32) << 24usize) & (4278190080u64 as u32))
+ ((0 | ((pad3 as u32 as u32) << 0usize) & (0xffffff as u32))
+ | ((type_ as u32 as u32) << 24usize) & (0xff000000 as u32))
}
}
diff --git a/tests/expectations/tests/c-empty-layout.rs b/tests/expectations/tests/c-empty-layout.rs
index c599b01b..a14022f5 100644
--- a/tests/expectations/tests/c-empty-layout.rs
+++ b/tests/expectations/tests/c-empty-layout.rs
@@ -5,16 +5,18 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
-pub struct Foo {
-}
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Foo {}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 0usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 0usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/canonical_path_without_namespacing.rs b/tests/expectations/tests/canonical_path_without_namespacing.rs
index d518a153..02955e44 100644
--- a/tests/expectations/tests/canonical_path_without_namespacing.rs
+++ b/tests/expectations/tests/canonical_path_without_namespacing.rs
@@ -5,21 +5,24 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
}
extern "C" {
- #[link_name = "_Z3bazPN3foo3BarE"]
+ #[link_name = "\u{1}_Z3bazPN3foo3BarE"]
pub fn baz(arg1: *mut Bar);
}
diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs
index 1e45c743..9f7834ae 100644
--- a/tests/expectations/tests/char.rs
+++ b/tests/expectations/tests/char.rs
@@ -8,7 +8,7 @@ pub type Char = ::std::os::raw::c_char;
pub type SChar = ::std::os::raw::c_schar;
pub type UChar = ::std::os::raw::c_uchar;
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Test {
pub ch: ::std::os::raw::c_char,
pub u: ::std::os::raw::c_uchar,
@@ -25,71 +25,134 @@ pub struct Test {
}
#[test]
fn bindgen_test_layout_Test() {
- assert_eq!(::std::mem::size_of::<Test>() , 12usize , concat ! (
- "Size of: " , stringify ! ( Test ) ));
- assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Test ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . ch as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( ch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . u as * const _ as usize } ,
- 1usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( u ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . d as * const _ as usize } ,
- 2usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( d ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . cch as * const _ as usize } ,
- 3usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( cch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . cu as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( cu ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . cd as * const _ as usize } ,
- 5usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( cd ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Cch as * const _ as usize } ,
- 6usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Cch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Cu as * const _ as usize } ,
- 7usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Cu ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Cd as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Cd ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Ccch as * const _ as usize } ,
- 9usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Ccch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Ccu as * const _ as usize } ,
- 10usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Ccu ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Ccd as * const _ as usize } ,
- 11usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Ccd ) ));
-}
-impl Clone for Test {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test>(),
+ 12usize,
+ concat!("Size of: ", stringify!(Test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Test))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).ch as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(ch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).u as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(u)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).d as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(d)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).cch as *const _ as usize },
+ 3usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(cch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).cu as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(cu)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).cd as *const _ as usize },
+ 5usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(cd)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Cch as *const _ as usize },
+ 6usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Cch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Cu as *const _ as usize },
+ 7usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Cu)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Cd as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Cd)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Ccch as *const _ as usize },
+ 9usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Ccch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Ccu as *const _ as usize },
+ 10usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Ccu)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Ccd as *const _ as usize },
+ 11usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Ccd)
+ )
+ );
}
diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs
index d1216655..784a42d3 100644
--- a/tests/expectations/tests/class.rs
+++ b/tests/expectations/tests/class.rs
@@ -7,13 +7,15 @@
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
-impl <T> __IncompleteArrayField<T> {
+impl<T> __IncompleteArrayField<T> {
#[inline]
pub fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData)
}
#[inline]
- pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
#[inline]
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
::std::mem::transmute(self)
@@ -27,43 +29,56 @@ impl <T> __IncompleteArrayField<T> {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
-impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
-impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct C {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_char; 33usize],
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 40usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . a as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . big_array as * const _ as usize }
- , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( big_array ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 40usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).big_array as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(big_array)
+ )
+ );
}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct C_with_zero_length_array {
@@ -73,33 +88,94 @@ pub struct C_with_zero_length_array {
}
#[test]
fn bindgen_test_layout_C_with_zero_length_array() {
- assert_eq!(::std::mem::size_of::<C_with_zero_length_array>() , 40usize ,
- concat ! (
- "Size of: " , stringify ! ( C_with_zero_length_array ) ));
- assert_eq! (::std::mem::align_of::<C_with_zero_length_array>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( C_with_zero_length_array ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_with_zero_length_array ) ) . a as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- C_with_zero_length_array ) , "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_with_zero_length_array ) ) . big_array
- as * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! (
- C_with_zero_length_array ) , "::" , stringify ! ( big_array )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_with_zero_length_array ) ) .
- zero_length_array as * const _ as usize } , 37usize , concat !
- (
- "Alignment of field: " , stringify ! (
- C_with_zero_length_array ) , "::" , stringify ! (
- zero_length_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array>(),
+ 40usize,
+ concat!("Size of: ", stringify!(C_with_zero_length_array))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_zero_length_array))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_with_zero_length_array)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_with_zero_length_array)).big_array as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array),
+ "::",
+ stringify!(big_array)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const C_with_zero_length_array)).zero_length_array as *const _ as usize
+ },
+ 37usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array),
+ "::",
+ stringify!(zero_length_array)
+ )
+ );
}
impl Default for C_with_zero_length_array {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[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() {
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(C_with_zero_length_array_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_zero_length_array_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_with_zero_length_array_2)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array_2),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const C_with_zero_length_array_2)).zero_length_array as *const _ as usize
+ },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array_2),
+ "::",
+ stringify!(zero_length_array)
+ )
+ );
}
#[repr(C)]
pub struct C_with_incomplete_array {
@@ -109,15 +185,40 @@ pub struct C_with_incomplete_array {
}
#[test]
fn bindgen_test_layout_C_with_incomplete_array() {
- assert_eq!(::std::mem::size_of::<C_with_incomplete_array>() , 40usize ,
- concat ! (
- "Size of: " , stringify ! ( C_with_incomplete_array ) ));
- assert_eq! (::std::mem::align_of::<C_with_incomplete_array>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( C_with_incomplete_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_with_incomplete_array>(),
+ 40usize,
+ concat!("Size of: ", stringify!(C_with_incomplete_array))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_incomplete_array>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_incomplete_array))
+ );
}
impl Default for C_with_incomplete_array {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[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() {
+ assert_eq!(
+ ::std::mem::size_of::<C_with_incomplete_array_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(C_with_incomplete_array_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_incomplete_array_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_incomplete_array_2))
+ );
}
#[repr(C)]
pub struct C_with_zero_length_array_and_incomplete_array {
@@ -128,34 +229,81 @@ pub struct C_with_zero_length_array_and_incomplete_array {
}
#[test]
fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() {
- assert_eq!(::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>()
- , 40usize , concat ! (
- "Size of: " , stringify ! (
- C_with_zero_length_array_and_incomplete_array ) ));
- assert_eq! (::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>()
- , 4usize , concat ! (
- "Alignment of " , stringify ! (
- C_with_zero_length_array_and_incomplete_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>(),
+ 40usize,
+ concat!(
+ "Size of: ",
+ stringify!(C_with_zero_length_array_and_incomplete_array)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(C_with_zero_length_array_and_incomplete_array)
+ )
+ );
}
impl Default for C_with_zero_length_array_and_incomplete_array {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[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() {
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array_2>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(C_with_zero_length_array_and_incomplete_array_2)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array_2>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(C_with_zero_length_array_and_incomplete_array_2)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct WithDtor {
pub b: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_WithDtor() {
- assert_eq!(::std::mem::size_of::<WithDtor>() , 4usize , concat ! (
- "Size of: " , stringify ! ( WithDtor ) ));
- assert_eq! (::std::mem::align_of::<WithDtor>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithDtor ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithDtor ) ) . b as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithDtor ) , "::" ,
- stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WithDtor>(),
+ 4usize,
+ concat!("Size of: ", stringify!(WithDtor))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithDtor>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithDtor))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithDtor)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithDtor),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[repr(C)]
pub struct IncompleteArrayNonCopiable {
@@ -164,19 +312,24 @@ pub struct IncompleteArrayNonCopiable {
}
#[test]
fn bindgen_test_layout_IncompleteArrayNonCopiable() {
- assert_eq!(::std::mem::size_of::<IncompleteArrayNonCopiable>() , 8usize ,
- concat ! (
- "Size of: " , stringify ! ( IncompleteArrayNonCopiable ) ));
- assert_eq! (::std::mem::align_of::<IncompleteArrayNonCopiable>() , 8usize
- , concat ! (
- "Alignment of " , stringify ! ( IncompleteArrayNonCopiable )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<IncompleteArrayNonCopiable>(),
+ 8usize,
+ concat!("Size of: ", stringify!(IncompleteArrayNonCopiable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<IncompleteArrayNonCopiable>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable))
+ );
}
impl Default for IncompleteArrayNonCopiable {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union Union {
pub d: f32,
pub i: ::std::os::raw::c_int,
@@ -184,92 +337,120 @@ pub union Union {
}
#[test]
fn bindgen_test_layout_Union() {
- assert_eq!(::std::mem::size_of::<Union>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Union ) ));
- assert_eq! (::std::mem::align_of::<Union>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Union ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Union ) ) . d as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Union ) , "::" ,
- stringify ! ( d ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Union ) ) . i as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Union ) , "::" ,
- stringify ! ( i ) ));
-}
-impl Clone for Union {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Union>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Union))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Union>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Union))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Union)).d as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Union),
+ "::",
+ stringify!(d)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Union)).i as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Union),
+ "::",
+ stringify!(i)
+ )
+ );
}
impl Default for Union {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct WithUnion {
pub data: Union,
}
#[test]
fn bindgen_test_layout_WithUnion() {
- assert_eq!(::std::mem::size_of::<WithUnion>() , 4usize , concat ! (
- "Size of: " , stringify ! ( WithUnion ) ));
- assert_eq! (::std::mem::align_of::<WithUnion>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithUnion ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithUnion ) ) . data as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithUnion ) , "::" ,
- stringify ! ( data ) ));
-}
-impl Clone for WithUnion {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<WithUnion>(),
+ 4usize,
+ concat!("Size of: ", stringify!(WithUnion))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithUnion>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithUnion))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithUnion)).data as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithUnion),
+ "::",
+ stringify!(data)
+ )
+ );
}
impl Default for WithUnion {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct RealAbstractionWithTonsOfMethods {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() {
- assert_eq!(::std::mem::size_of::<RealAbstractionWithTonsOfMethods>() ,
- 1usize , concat ! (
- "Size of: " , stringify ! ( RealAbstractionWithTonsOfMethods )
- ));
- assert_eq! (::std::mem::align_of::<RealAbstractionWithTonsOfMethods>() ,
- 1usize , concat ! (
- "Alignment of " , stringify ! (
- RealAbstractionWithTonsOfMethods ) ));
+ assert_eq!(
+ ::std::mem::size_of::<RealAbstractionWithTonsOfMethods>(),
+ 1usize,
+ concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<RealAbstractionWithTonsOfMethods>(),
+ 1usize,
+ concat!(
+ "Alignment of ",
+ stringify!(RealAbstractionWithTonsOfMethods)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZNK32RealAbstractionWithTonsOfMethods3barEv"]
- pub fn RealAbstractionWithTonsOfMethods_bar(this:
- *const RealAbstractionWithTonsOfMethods);
+ #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"]
+ pub fn RealAbstractionWithTonsOfMethods_bar(this: *const RealAbstractionWithTonsOfMethods);
}
extern "C" {
- #[link_name = "_ZN32RealAbstractionWithTonsOfMethods3barEv"]
- pub fn RealAbstractionWithTonsOfMethods_bar1(this:
- *mut RealAbstractionWithTonsOfMethods);
+ #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"]
+ pub fn RealAbstractionWithTonsOfMethods_bar1(this: *mut RealAbstractionWithTonsOfMethods);
}
extern "C" {
- #[link_name = "_ZN32RealAbstractionWithTonsOfMethods3barEi"]
- pub fn RealAbstractionWithTonsOfMethods_bar2(this:
- *mut RealAbstractionWithTonsOfMethods,
- foo: ::std::os::raw::c_int);
+ #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"]
+ pub fn RealAbstractionWithTonsOfMethods_bar2(
+ this: *mut RealAbstractionWithTonsOfMethods,
+ foo: ::std::os::raw::c_int,
+ );
}
extern "C" {
- #[link_name = "_ZN32RealAbstractionWithTonsOfMethods3staEv"]
+ #[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) }
+ pub unsafe fn bar(&self) {
+ RealAbstractionWithTonsOfMethods_bar(self)
+ }
#[inline]
pub unsafe fn bar1(&mut self) {
RealAbstractionWithTonsOfMethods_bar1(self)
@@ -279,5 +460,7 @@ impl RealAbstractionWithTonsOfMethods {
RealAbstractionWithTonsOfMethods_bar2(self, foo)
}
#[inline]
- pub unsafe fn sta() { RealAbstractionWithTonsOfMethods_sta() }
+ pub unsafe fn sta() {
+ RealAbstractionWithTonsOfMethods_sta()
+ }
}
diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs
index 8ccf4e01..c54edcdb 100644
--- a/tests/expectations/tests/class_1_0.rs
+++ b/tests/expectations/tests/class_1_0.rs
@@ -7,13 +7,15 @@
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
-impl <T> __IncompleteArrayField<T> {
+impl<T> __IncompleteArrayField<T> {
#[inline]
pub fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData)
}
#[inline]
- pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
#[inline]
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
::std::mem::transmute(self)
@@ -27,47 +29,61 @@ impl <T> __IncompleteArrayField<T> {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
-impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
-impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Copy)]
pub struct C {
@@ -76,25 +92,46 @@ pub struct C {
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 40usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . a as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . big_array as * const _ as usize }
- , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( big_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 40usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).big_array as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(big_array)
+ )
+ );
}
impl Clone for C {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+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 {
@@ -104,33 +141,94 @@ pub struct C_with_zero_length_array {
}
#[test]
fn bindgen_test_layout_C_with_zero_length_array() {
- assert_eq!(::std::mem::size_of::<C_with_zero_length_array>() , 40usize ,
- concat ! (
- "Size of: " , stringify ! ( C_with_zero_length_array ) ));
- assert_eq! (::std::mem::align_of::<C_with_zero_length_array>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( C_with_zero_length_array ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_with_zero_length_array ) ) . a as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- C_with_zero_length_array ) , "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_with_zero_length_array ) ) . big_array
- as * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! (
- C_with_zero_length_array ) , "::" , stringify ! ( big_array )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_with_zero_length_array ) ) .
- zero_length_array as * const _ as usize } , 37usize , concat !
- (
- "Alignment of field: " , stringify ! (
- C_with_zero_length_array ) , "::" , stringify ! (
- zero_length_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array>(),
+ 40usize,
+ concat!("Size of: ", stringify!(C_with_zero_length_array))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_zero_length_array))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_with_zero_length_array)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_with_zero_length_array)).big_array as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array),
+ "::",
+ stringify!(big_array)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const C_with_zero_length_array)).zero_length_array as *const _ as usize
+ },
+ 37usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array),
+ "::",
+ stringify!(zero_length_array)
+ )
+ );
}
impl Default for C_with_zero_length_array {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[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() {
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(C_with_zero_length_array_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_zero_length_array_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_with_zero_length_array_2)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array_2),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const C_with_zero_length_array_2)).zero_length_array as *const _ as usize
+ },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_with_zero_length_array_2),
+ "::",
+ stringify!(zero_length_array)
+ )
+ );
}
#[repr(C)]
pub struct C_with_incomplete_array {
@@ -140,15 +238,40 @@ pub struct C_with_incomplete_array {
}
#[test]
fn bindgen_test_layout_C_with_incomplete_array() {
- assert_eq!(::std::mem::size_of::<C_with_incomplete_array>() , 40usize ,
- concat ! (
- "Size of: " , stringify ! ( C_with_incomplete_array ) ));
- assert_eq! (::std::mem::align_of::<C_with_incomplete_array>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( C_with_incomplete_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_with_incomplete_array>(),
+ 40usize,
+ concat!("Size of: ", stringify!(C_with_incomplete_array))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_incomplete_array>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_incomplete_array))
+ );
}
impl Default for C_with_incomplete_array {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[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() {
+ assert_eq!(
+ ::std::mem::size_of::<C_with_incomplete_array_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(C_with_incomplete_array_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_incomplete_array_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_with_incomplete_array_2))
+ );
}
#[repr(C)]
pub struct C_with_zero_length_array_and_incomplete_array {
@@ -159,17 +282,53 @@ pub struct C_with_zero_length_array_and_incomplete_array {
}
#[test]
fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() {
- assert_eq!(::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>()
- , 40usize , concat ! (
- "Size of: " , stringify ! (
- C_with_zero_length_array_and_incomplete_array ) ));
- assert_eq! (::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>()
- , 4usize , concat ! (
- "Alignment of " , stringify ! (
- C_with_zero_length_array_and_incomplete_array ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>(),
+ 40usize,
+ concat!(
+ "Size of: ",
+ stringify!(C_with_zero_length_array_and_incomplete_array)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(C_with_zero_length_array_and_incomplete_array)
+ )
+ );
}
impl Default for C_with_zero_length_array_and_incomplete_array {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[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() {
+ assert_eq!(
+ ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array_2>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(C_with_zero_length_array_and_incomplete_array_2)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array_2>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(C_with_zero_length_array_and_incomplete_array_2)
+ )
+ );
}
#[repr(C)]
#[derive(Debug, Default, Hash, PartialEq, Eq)]
@@ -178,15 +337,26 @@ pub struct WithDtor {
}
#[test]
fn bindgen_test_layout_WithDtor() {
- assert_eq!(::std::mem::size_of::<WithDtor>() , 4usize , concat ! (
- "Size of: " , stringify ! ( WithDtor ) ));
- assert_eq! (::std::mem::align_of::<WithDtor>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithDtor ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithDtor ) ) . b as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithDtor ) , "::" ,
- stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WithDtor>(),
+ 4usize,
+ concat!("Size of: ", stringify!(WithDtor))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithDtor>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithDtor))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithDtor)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithDtor),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[repr(C)]
pub struct IncompleteArrayNonCopiable {
@@ -195,16 +365,21 @@ pub struct IncompleteArrayNonCopiable {
}
#[test]
fn bindgen_test_layout_IncompleteArrayNonCopiable() {
- assert_eq!(::std::mem::size_of::<IncompleteArrayNonCopiable>() , 8usize ,
- concat ! (
- "Size of: " , stringify ! ( IncompleteArrayNonCopiable ) ));
- assert_eq! (::std::mem::align_of::<IncompleteArrayNonCopiable>() , 8usize
- , concat ! (
- "Alignment of " , stringify ! ( IncompleteArrayNonCopiable )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<IncompleteArrayNonCopiable>(),
+ 8usize,
+ concat!("Size of: ", stringify!(IncompleteArrayNonCopiable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<IncompleteArrayNonCopiable>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable))
+ );
}
impl Default for IncompleteArrayNonCopiable {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq)]
@@ -215,23 +390,41 @@ pub struct Union {
}
#[test]
fn bindgen_test_layout_Union() {
- assert_eq!(::std::mem::size_of::<Union>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Union ) ));
- assert_eq! (::std::mem::align_of::<Union>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Union ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Union ) ) . d as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Union ) , "::" ,
- stringify ! ( d ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Union ) ) . i as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Union ) , "::" ,
- stringify ! ( i ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Union>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Union))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Union>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Union))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Union)).d as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Union),
+ "::",
+ stringify!(d)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Union)).i as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Union),
+ "::",
+ stringify!(i)
+ )
+ );
}
impl Clone for Union {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq)]
@@ -240,18 +433,31 @@ pub struct WithUnion {
}
#[test]
fn bindgen_test_layout_WithUnion() {
- assert_eq!(::std::mem::size_of::<WithUnion>() , 4usize , concat ! (
- "Size of: " , stringify ! ( WithUnion ) ));
- assert_eq! (::std::mem::align_of::<WithUnion>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithUnion ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithUnion ) ) . data as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithUnion ) , "::" ,
- stringify ! ( data ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WithUnion>(),
+ 4usize,
+ concat!("Size of: ", stringify!(WithUnion))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithUnion>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithUnion))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithUnion)).data as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithUnion),
+ "::",
+ stringify!(data)
+ )
+ );
}
impl Clone for WithUnion {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -260,41 +466,49 @@ pub struct RealAbstractionWithTonsOfMethods {
}
#[test]
fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() {
- assert_eq!(::std::mem::size_of::<RealAbstractionWithTonsOfMethods>() ,
- 1usize , concat ! (
- "Size of: " , stringify ! ( RealAbstractionWithTonsOfMethods )
- ));
- assert_eq! (::std::mem::align_of::<RealAbstractionWithTonsOfMethods>() ,
- 1usize , concat ! (
- "Alignment of " , stringify ! (
- RealAbstractionWithTonsOfMethods ) ));
+ assert_eq!(
+ ::std::mem::size_of::<RealAbstractionWithTonsOfMethods>(),
+ 1usize,
+ concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<RealAbstractionWithTonsOfMethods>(),
+ 1usize,
+ concat!(
+ "Alignment of ",
+ stringify!(RealAbstractionWithTonsOfMethods)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZNK32RealAbstractionWithTonsOfMethods3barEv"]
- pub fn RealAbstractionWithTonsOfMethods_bar(this:
- *const RealAbstractionWithTonsOfMethods);
+ #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"]
+ pub fn RealAbstractionWithTonsOfMethods_bar(this: *const RealAbstractionWithTonsOfMethods);
}
extern "C" {
- #[link_name = "_ZN32RealAbstractionWithTonsOfMethods3barEv"]
- pub fn RealAbstractionWithTonsOfMethods_bar1(this:
- *mut RealAbstractionWithTonsOfMethods);
+ #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"]
+ pub fn RealAbstractionWithTonsOfMethods_bar1(this: *mut RealAbstractionWithTonsOfMethods);
}
extern "C" {
- #[link_name = "_ZN32RealAbstractionWithTonsOfMethods3barEi"]
- pub fn RealAbstractionWithTonsOfMethods_bar2(this:
- *mut RealAbstractionWithTonsOfMethods,
- foo: ::std::os::raw::c_int);
+ #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"]
+ pub fn RealAbstractionWithTonsOfMethods_bar2(
+ this: *mut RealAbstractionWithTonsOfMethods,
+ foo: ::std::os::raw::c_int,
+ );
}
extern "C" {
- #[link_name = "_ZN32RealAbstractionWithTonsOfMethods3staEv"]
+ #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"]
pub fn RealAbstractionWithTonsOfMethods_sta();
}
impl Clone for RealAbstractionWithTonsOfMethods {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl RealAbstractionWithTonsOfMethods {
#[inline]
- pub unsafe fn bar(&self) { RealAbstractionWithTonsOfMethods_bar(self) }
+ pub unsafe fn bar(&self) {
+ RealAbstractionWithTonsOfMethods_bar(self)
+ }
#[inline]
pub unsafe fn bar1(&mut self) {
RealAbstractionWithTonsOfMethods_bar1(self)
@@ -304,5 +518,7 @@ impl RealAbstractionWithTonsOfMethods {
RealAbstractionWithTonsOfMethods_bar2(self, foo)
}
#[inline]
- pub unsafe fn sta() { RealAbstractionWithTonsOfMethods_sta() }
+ pub unsafe fn sta() {
+ RealAbstractionWithTonsOfMethods_sta()
+ }
}
diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs
index b0062c9b..e9d02479 100644
--- a/tests/expectations/tests/class_nested.rs
+++ b/tests/expectations/tests/class_nested.rs
@@ -5,12 +5,12 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct A {
pub member_a: ::std::os::raw::c_int,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct A_B {
pub member_b: ::std::os::raw::c_int,
}
@@ -37,11 +37,6 @@ fn bindgen_test_layout_A_B() {
)
);
}
-impl Clone for A_B {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct A_D<T> {
@@ -76,13 +71,8 @@ fn bindgen_test_layout_A() {
)
);
}
-impl Clone for A {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct A_C {
pub baz: ::std::os::raw::c_int,
}
@@ -109,13 +99,8 @@ fn bindgen_test_layout_A_C() {
)
);
}
-impl Clone for A_C {
- fn clone(&self) -> Self {
- *self
- }
-}
extern "C" {
- #[link_name = "var"]
+ #[link_name = "\u{1}var"]
pub static mut var: A_B;
}
#[test]
@@ -125,30 +110,49 @@ fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() {
4usize,
concat!(
"Size of template specialization: ",
- stringify ! ( A_D < :: std :: os :: raw :: c_int > )
+ stringify!(A_D<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A_D<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(A_D<::std::os::raw::c_int>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < A_D < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( A_D < :: std :: os :: raw :: c_int > ) ) );
}
extern "C" {
- #[link_name = "baz"]
+ #[link_name = "\u{1}baz"]
pub static mut baz: A_D<::std::os::raw::c_int>;
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct D {
pub member: A_B,
}
#[test]
fn bindgen_test_layout_D() {
- assert_eq ! ( :: std :: mem :: size_of :: < D > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( D ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < D > ( ) , 4usize , concat ! ( "Alignment of " , stringify ! ( D ) ) );
- assert_eq ! ( unsafe { & ( * ( 0 as * const D ) ) . member as * const _ as usize } , 0usize , concat ! ( "Alignment of field: " , stringify ! ( D ) , "::" , stringify ! ( member ) ) );
-}
-impl Clone for D {
- fn clone(&self) -> Self {
- *self
- }
+ assert_eq!(
+ ::std::mem::size_of::<D>(),
+ 4usize,
+ concat!("Size of: ", stringify!(D))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<D>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(D))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const D)).member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(D),
+ "::",
+ stringify!(member)
+ )
+ );
}
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs
index 7fc05c5f..01ae9474 100644
--- a/tests/expectations/tests/class_no_members.rs
+++ b/tests/expectations/tests/class_no_members.rs
@@ -5,56 +5,66 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct whatever {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_whatever() {
- assert_eq!(::std::mem::size_of::<whatever>() , 1usize , concat ! (
- "Size of: " , stringify ! ( whatever ) ));
- assert_eq! (::std::mem::align_of::<whatever>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( whatever ) ));
-}
-impl Clone for whatever {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<whatever>(),
+ 1usize,
+ concat!("Size of: ", stringify!(whatever))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<whatever>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(whatever))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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::<whatever_child>() , 1usize , concat ! (
- "Size of: " , stringify ! ( whatever_child ) ));
- assert_eq! (::std::mem::align_of::<whatever_child>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( whatever_child ) ));
-}
-impl Clone for whatever_child {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<whatever_child>(),
+ 1usize,
+ concat!("Size of: ", stringify!(whatever_child))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<whatever_child>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(whatever_child))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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() {
- assert_eq!(::std::mem::size_of::<whatever_child_with_member>() , 4usize ,
- concat ! (
- "Size of: " , stringify ! ( whatever_child_with_member ) ));
- assert_eq! (::std::mem::align_of::<whatever_child_with_member>() , 4usize
- , concat ! (
- "Alignment of " , stringify ! ( whatever_child_with_member )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const whatever_child_with_member ) ) . m_member
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- whatever_child_with_member ) , "::" , stringify ! ( m_member )
- ));
-}
-impl Clone for whatever_child_with_member {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<whatever_child_with_member>(),
+ 4usize,
+ concat!("Size of: ", stringify!(whatever_child_with_member))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<whatever_child_with_member>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(whatever_child_with_member))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const whatever_child_with_member)).m_member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(whatever_child_with_member),
+ "::",
+ stringify!(m_member)
+ )
+ );
}
diff --git a/tests/expectations/tests/class_static.rs b/tests/expectations/tests/class_static.rs
index 84f129df..c28366c1 100644
--- a/tests/expectations/tests/class_static.rs
+++ b/tests/expectations/tests/class_static.rs
@@ -5,30 +5,32 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct MyClass {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN7MyClass7exampleE"]
+ #[link_name = "\u{1}_ZN7MyClass7exampleE"]
pub static mut MyClass_example: *const ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "_ZN7MyClass26example_check_no_collisionE"]
- pub static mut MyClass_example_check_no_collision:
- *const ::std::os::raw::c_int;
+ #[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::<MyClass>() , 1usize , concat ! (
- "Size of: " , stringify ! ( MyClass ) ));
- assert_eq! (::std::mem::align_of::<MyClass>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( MyClass ) ));
-}
-impl Clone for MyClass {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<MyClass>(),
+ 1usize,
+ concat!("Size of: ", stringify!(MyClass))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<MyClass>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(MyClass))
+ );
}
extern "C" {
- #[link_name = "_ZL26example_check_no_collision"]
+ #[link_name = "\u{1}_ZL26example_check_no_collision"]
pub static mut example_check_no_collision: *const ::std::os::raw::c_int;
}
diff --git a/tests/expectations/tests/class_static_const.rs b/tests/expectations/tests/class_static_const.rs
index 9a4b5425..c0945c43 100644
--- a/tests/expectations/tests/class_static_const.rs
+++ b/tests/expectations/tests/class_static_const.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct A {
pub _address: u8,
}
@@ -14,11 +14,14 @@ pub const A_b: i32 = 63;
pub const A_c: u32 = 255;
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
-}
-impl Clone for A {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 1usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(A))
+ );
}
diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs
index af73ae3b..95b2a7fd 100644
--- a/tests/expectations/tests/class_use_as.rs
+++ b/tests/expectations/tests/class_use_as.rs
@@ -7,7 +7,7 @@
/// <div rustbindgen="true" replaces="whatever"></div>
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct whatever {
pub replacement: ::std::os::raw::c_int,
}
@@ -34,13 +34,8 @@ fn bindgen_test_layout_whatever() {
)
);
}
-impl Clone for whatever {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct container {
pub c: whatever,
}
@@ -67,8 +62,3 @@ fn bindgen_test_layout_container() {
)
);
}
-impl Clone for container {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs
index 08e3aa88..36ad6307 100644
--- a/tests/expectations/tests/class_with_dtor.rs
+++ b/tests/expectations/tests/class_with_dtor.rs
@@ -56,8 +56,15 @@ fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
8usize,
concat!(
"Size of template specialization: ",
- stringify ! ( HandleWithDtor < :: std :: os :: raw :: c_int > )
+ stringify!(HandleWithDtor<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(HandleWithDtor<::std::os::raw::c_int>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < HandleWithDtor < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( HandleWithDtor < :: std :: os :: raw :: c_int > ) ) );
}
diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs
index 03df6008..4848bc17 100644
--- a/tests/expectations/tests/class_with_inner_struct.rs
+++ b/tests/expectations/tests/class_with_inner_struct.rs
@@ -5,152 +5,213 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
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)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<A_Segment>() , 8usize , concat ! (
- "Size of: " , stringify ! ( A_Segment ) ));
- assert_eq! (::std::mem::align_of::<A_Segment>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( A_Segment ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A_Segment ) ) . begin as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A_Segment ) , "::" ,
- stringify ! ( begin ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A_Segment ) ) . end as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( A_Segment ) , "::" ,
- stringify ! ( end ) ));
-}
-impl Clone for A_Segment {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A_Segment>(),
+ 8usize,
+ concat!("Size of: ", stringify!(A_Segment))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A_Segment>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A_Segment))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A_Segment)).begin as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A_Segment),
+ "::",
+ stringify!(begin)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A_Segment)).end as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A_Segment),
+ "::",
+ stringify!(end)
+ )
+ );
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union A__bindgen_ty_1 {
pub f: ::std::os::raw::c_int,
_bindgen_union_align: u32,
}
#[test]
fn bindgen_test_layout_A__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<A__bindgen_ty_1>() , 4usize , concat ! (
- "Size of: " , stringify ! ( A__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<A__bindgen_ty_1>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( A__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A__bindgen_ty_1 ) ) . f as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A__bindgen_ty_1 ) ,
- "::" , stringify ! ( f ) ));
-}
-impl Clone for A__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(A__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A__bindgen_ty_1)).f as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A__bindgen_ty_1),
+ "::",
+ stringify!(f)
+ )
+ );
}
impl Default for A__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union A__bindgen_ty_2 {
pub d: ::std::os::raw::c_int,
_bindgen_union_align: u32,
}
#[test]
fn bindgen_test_layout_A__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<A__bindgen_ty_2>() , 4usize , concat ! (
- "Size of: " , stringify ! ( A__bindgen_ty_2 ) ));
- assert_eq! (::std::mem::align_of::<A__bindgen_ty_2>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( A__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A__bindgen_ty_2 ) ) . d as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A__bindgen_ty_2 ) ,
- "::" , stringify ! ( d ) ));
-}
-impl Clone for A__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A__bindgen_ty_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(A__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A__bindgen_ty_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A__bindgen_ty_2)).d as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A__bindgen_ty_2),
+ "::",
+ stringify!(d)
+ )
+ );
}
impl Default for A__bindgen_ty_2 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 12usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . c as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A ) , "::" , stringify
- ! ( c ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A ) ) . named_union as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( A ) , "::" , stringify
- ! ( named_union ) ));
-}
-impl Clone for A {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 12usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A)).c as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(A), "::", stringify!(c))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A)).named_union as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A),
+ "::",
+ stringify!(named_union)
+ )
+ );
}
impl Default for A {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct B {
pub d: ::std::os::raw::c_uint,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<B_Segment>() , 8usize , concat ! (
- "Size of: " , stringify ! ( B_Segment ) ));
- assert_eq! (::std::mem::align_of::<B_Segment>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( B_Segment ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const B_Segment ) ) . begin as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( B_Segment ) , "::" ,
- stringify ! ( begin ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const B_Segment ) ) . end as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( B_Segment ) , "::" ,
- stringify ! ( end ) ));
-}
-impl Clone for B_Segment {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<B_Segment>(),
+ 8usize,
+ concat!("Size of: ", stringify!(B_Segment))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B_Segment>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(B_Segment))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B_Segment)).begin as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(B_Segment),
+ "::",
+ stringify!(begin)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B_Segment)).end as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(B_Segment),
+ "::",
+ stringify!(end)
+ )
+ );
}
#[test]
fn bindgen_test_layout_B() {
- assert_eq!(::std::mem::size_of::<B>() , 4usize , concat ! (
- "Size of: " , stringify ! ( B ) ));
- assert_eq! (::std::mem::align_of::<B>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( B ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const B ) ) . d as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( B ) , "::" , stringify
- ! ( d ) ));
-}
-impl Clone for B {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 4usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(B))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B)).d as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(B), "::", stringify!(d))
+ );
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -161,20 +222,20 @@ pub enum StepSyntax {
FunctionalWithEndKeyword = 3,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct C {
pub d: ::std::os::raw::c_uint,
pub __bindgen_anon_1: C__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union C__bindgen_ty_1 {
pub mFunc: C__bindgen_ty_1__bindgen_ty_1,
pub __bindgen_anon_1: C__bindgen_ty_1__bindgen_ty_2,
_bindgen_union_align: [u32; 4usize],
}
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct C__bindgen_ty_1__bindgen_ty_1 {
pub mX1: f32,
pub mY1: f32,
@@ -183,133 +244,188 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_1>() ,
- 16usize , concat ! (
- "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1
- ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY1
- as * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX2
- as * const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX2 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY2
- as * const _ as usize } , 12usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY2 )
- ));
-}
-impl Clone for C__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_1>(),
+ 16usize,
+ concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mX1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mX1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mY1 as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mY1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mX2 as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mX2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mY2 as *const _ as usize },
+ 12usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mY2)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[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() {
- assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>() , 8usize
- , concat ! (
- "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2 ) ));
- assert_eq! (::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2
- ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) .
- mStepSyntax as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! (
- mStepSyntax ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) .
- mSteps as * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( mSteps
- ) ));
-}
-impl Clone for C__bindgen_ty_1__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>(),
+ 8usize,
+ concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_2)).mStepSyntax as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(mStepSyntax)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_2)).mSteps as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(mSteps)
+ )
+ );
}
impl Default for C__bindgen_ty_1__bindgen_ty_2 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_C__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<C__bindgen_ty_1>() , 16usize , concat ! (
- "Size of: " , stringify ! ( C__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<C__bindgen_ty_1>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( C__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1 ) ) . mFunc as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C__bindgen_ty_1 ) ,
- "::" , stringify ! ( mFunc ) ));
-}
-impl Clone for C__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C__bindgen_ty_1>(),
+ 16usize,
+ concat!("Size of: ", stringify!(C__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1)).mFunc as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1),
+ "::",
+ stringify!(mFunc)
+ )
+ );
}
impl Default for C__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<C_Segment>() , 8usize , concat ! (
- "Size of: " , stringify ! ( C_Segment ) ));
- assert_eq! (::std::mem::align_of::<C_Segment>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C_Segment ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_Segment ) ) . begin as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C_Segment ) , "::" ,
- stringify ! ( begin ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_Segment ) ) . end as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( C_Segment ) , "::" ,
- stringify ! ( end ) ));
-}
-impl Clone for C_Segment {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C_Segment>(),
+ 8usize,
+ concat!("Size of: ", stringify!(C_Segment))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_Segment>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_Segment))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_Segment)).begin as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_Segment),
+ "::",
+ stringify!(begin)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_Segment)).end as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_Segment),
+ "::",
+ stringify!(end)
+ )
+ );
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 20usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( d ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 20usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).d as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(d))
+ );
}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs
index 42376dee..07a2fe48 100644
--- a/tests/expectations/tests/class_with_inner_struct_1_0.rs
+++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct A {
@@ -50,23 +62,41 @@ pub struct A_Segment {
}
#[test]
fn bindgen_test_layout_A_Segment() {
- assert_eq!(::std::mem::size_of::<A_Segment>() , 8usize , concat ! (
- "Size of: " , stringify ! ( A_Segment ) ));
- assert_eq! (::std::mem::align_of::<A_Segment>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( A_Segment ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A_Segment ) ) . begin as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A_Segment ) , "::" ,
- stringify ! ( begin ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A_Segment ) ) . end as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( A_Segment ) , "::" ,
- stringify ! ( end ) ));
+ assert_eq!(
+ ::std::mem::size_of::<A_Segment>(),
+ 8usize,
+ concat!("Size of: ", stringify!(A_Segment))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A_Segment>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A_Segment))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A_Segment)).begin as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A_Segment),
+ "::",
+ stringify!(begin)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A_Segment)).end as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A_Segment),
+ "::",
+ stringify!(end)
+ )
+ );
}
impl Clone for A_Segment {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -76,18 +106,31 @@ pub struct A__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_A__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<A__bindgen_ty_1>() , 4usize , concat ! (
- "Size of: " , stringify ! ( A__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<A__bindgen_ty_1>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( A__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A__bindgen_ty_1 ) ) . f as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A__bindgen_ty_1 ) ,
- "::" , stringify ! ( f ) ));
+ assert_eq!(
+ ::std::mem::size_of::<A__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(A__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A__bindgen_ty_1)).f as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A__bindgen_ty_1),
+ "::",
+ stringify!(f)
+ )
+ );
}
impl Clone for A__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -97,37 +140,64 @@ pub struct A__bindgen_ty_2 {
}
#[test]
fn bindgen_test_layout_A__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<A__bindgen_ty_2>() , 4usize , concat ! (
- "Size of: " , stringify ! ( A__bindgen_ty_2 ) ));
- assert_eq! (::std::mem::align_of::<A__bindgen_ty_2>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( A__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A__bindgen_ty_2 ) ) . d as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A__bindgen_ty_2 ) ,
- "::" , stringify ! ( d ) ));
+ assert_eq!(
+ ::std::mem::size_of::<A__bindgen_ty_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(A__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A__bindgen_ty_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A__bindgen_ty_2)).d as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A__bindgen_ty_2),
+ "::",
+ stringify!(d)
+ )
+ );
}
impl Clone for A__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 12usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . c as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A ) , "::" , stringify
- ! ( c ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A ) ) . named_union as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( A ) , "::" , stringify
- ! ( named_union ) ));
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 12usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A)).c as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(A), "::", stringify!(c))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A)).named_union as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(A),
+ "::",
+ stringify!(named_union)
+ )
+ );
}
impl Clone for A {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -142,37 +212,64 @@ pub struct B_Segment {
}
#[test]
fn bindgen_test_layout_B_Segment() {
- assert_eq!(::std::mem::size_of::<B_Segment>() , 8usize , concat ! (
- "Size of: " , stringify ! ( B_Segment ) ));
- assert_eq! (::std::mem::align_of::<B_Segment>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( B_Segment ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const B_Segment ) ) . begin as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( B_Segment ) , "::" ,
- stringify ! ( begin ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const B_Segment ) ) . end as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( B_Segment ) , "::" ,
- stringify ! ( end ) ));
+ assert_eq!(
+ ::std::mem::size_of::<B_Segment>(),
+ 8usize,
+ concat!("Size of: ", stringify!(B_Segment))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B_Segment>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(B_Segment))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B_Segment)).begin as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(B_Segment),
+ "::",
+ stringify!(begin)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B_Segment)).end as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(B_Segment),
+ "::",
+ stringify!(end)
+ )
+ );
}
impl Clone for B_Segment {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_B() {
- assert_eq!(::std::mem::size_of::<B>() , 4usize , concat ! (
- "Size of: " , stringify ! ( B ) ));
- assert_eq! (::std::mem::align_of::<B>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( B ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const B ) ) . d as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( B ) , "::" , stringify
- ! ( d ) ));
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 4usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(B))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B)).d as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(B), "::", stringify!(d))
+ );
}
impl Clone for B {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -205,40 +302,61 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_1>() ,
- 16usize , concat ! (
- "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1
- ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY1
- as * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX2
- as * const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX2 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY2
- as * const _ as usize } , 12usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY2 )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_1>(),
+ 16usize,
+ concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mX1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mX1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mY1 as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mY1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mX2 as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mX2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_1)).mY2 as *const _ as usize },
+ 12usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(mY2)
+ )
+ );
}
impl Clone for C__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
@@ -248,46 +366,74 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 {
}
#[test]
fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>() , 8usize
- , concat ! (
- "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2 ) ));
- assert_eq! (::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2
- ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) .
- mStepSyntax as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! (
- mStepSyntax ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) .
- mSteps as * const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! (
- C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( mSteps
- ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>(),
+ 8usize,
+ concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_2)).mStepSyntax as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(mStepSyntax)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1__bindgen_ty_2)).mSteps as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(mSteps)
+ )
+ );
}
impl Clone for C__bindgen_ty_1__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for C__bindgen_ty_1__bindgen_ty_2 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_C__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<C__bindgen_ty_1>() , 16usize , concat ! (
- "Size of: " , stringify ! ( C__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<C__bindgen_ty_1>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( C__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C__bindgen_ty_1 ) ) . mFunc as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C__bindgen_ty_1 ) ,
- "::" , stringify ! ( mFunc ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C__bindgen_ty_1>(),
+ 16usize,
+ concat!("Size of: ", stringify!(C__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C__bindgen_ty_1)).mFunc as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C__bindgen_ty_1),
+ "::",
+ stringify!(mFunc)
+ )
+ );
}
impl Clone for C__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -297,35 +443,62 @@ pub struct C_Segment {
}
#[test]
fn bindgen_test_layout_C_Segment() {
- assert_eq!(::std::mem::size_of::<C_Segment>() , 8usize , concat ! (
- "Size of: " , stringify ! ( C_Segment ) ));
- assert_eq! (::std::mem::align_of::<C_Segment>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C_Segment ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_Segment ) ) . begin as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C_Segment ) , "::" ,
- stringify ! ( begin ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C_Segment ) ) . end as * const _ as usize
- } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( C_Segment ) , "::" ,
- stringify ! ( end ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C_Segment>(),
+ 8usize,
+ concat!("Size of: ", stringify!(C_Segment))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C_Segment>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C_Segment))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_Segment)).begin as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_Segment),
+ "::",
+ stringify!(begin)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C_Segment)).end as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C_Segment),
+ "::",
+ stringify!(end)
+ )
+ );
}
impl Clone for C_Segment {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 20usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( d ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 20usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).d as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(d))
+ );
}
impl Clone for C {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs
index 159f2735..459d580c 100644
--- a/tests/expectations/tests/class_with_typedef.rs
+++ b/tests/expectations/tests/class_with_typedef.rs
@@ -6,7 +6,7 @@
pub type AnotherInt = ::std::os::raw::c_int;
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct C {
pub c: C_MyInt,
pub ptr: *mut C_MyInt,
@@ -18,59 +18,73 @@ 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() {
- assert_eq!(::std::mem::size_of::<C>() , 72usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . c as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( c ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . ptr as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( ptr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . arr as * const _ as usize } ,
- 16usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( arr ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize
- } , 56usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( d ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . other_ptr as * const _ as usize }
- , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( other_ptr ) ));
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 72usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).c as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(c))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).ptr as *const _ as usize },
+ 8usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(ptr))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).arr as *const _ as usize },
+ 16usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(arr))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).d as *const _ as usize },
+ 56usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(d))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).other_ptr as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(other_ptr)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZN1C6methodEi"]
+ #[link_name = "\u{1}_ZN1C6methodEi"]
pub fn C_method(this: *mut C, c: C_MyInt);
}
extern "C" {
- #[link_name = "_ZN1C9methodRefERi"]
+ #[link_name = "\u{1}_ZN1C9methodRefERi"]
pub fn C_methodRef(this: *mut C, c: *mut C_MyInt);
}
extern "C" {
- #[link_name = "_ZN1C16complexMethodRefERPKc"]
+ #[link_name = "\u{1}_ZN1C16complexMethodRefERPKc"]
pub fn C_complexMethodRef(this: *mut C, c: *mut C_Lookup);
}
extern "C" {
- #[link_name = "_ZN1C13anotherMethodEi"]
+ #[link_name = "\u{1}_ZN1C13anotherMethodEi"]
pub fn C_anotherMethod(this: *mut C, c: AnotherInt);
}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
-}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl C {
#[inline]
- pub unsafe fn method(&mut self, c: C_MyInt) { C_method(self, c) }
+ pub unsafe fn method(&mut self, c: C_MyInt) {
+ C_method(self, c)
+ }
#[inline]
pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) {
C_methodRef(self, c)
@@ -85,26 +99,31 @@ impl C {
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct D {
pub _base: C,
pub ptr: *mut C_MyInt,
}
#[test]
fn bindgen_test_layout_D() {
- assert_eq!(::std::mem::size_of::<D>() , 80usize , concat ! (
- "Size of: " , stringify ! ( D ) ));
- assert_eq! (::std::mem::align_of::<D>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( D ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const D ) ) . ptr as * const _ as usize } ,
- 72usize , concat ! (
- "Alignment of field: " , stringify ! ( D ) , "::" , stringify
- ! ( ptr ) ));
-}
-impl Clone for D {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<D>(),
+ 80usize,
+ concat!("Size of: ", stringify!(D))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<D>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(D))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const D)).ptr as *const _ as usize },
+ 72usize,
+ concat!("Alignment of field: ", stringify!(D), "::", stringify!(ptr))
+ );
}
impl Default for D {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs
index 127c1b0e..4fe2b5eb 100644
--- a/tests/expectations/tests/comment-indent.rs
+++ b/tests/expectations/tests/comment-indent.rs
@@ -12,7 +12,7 @@ pub mod root {
///
/// This class is really really interesting, look!
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
@@ -20,29 +20,35 @@ pub mod root {
///
/// This class is not so interesting, but worth a bit of docs too!
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Foo_Bar {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo_Bar() {
- assert_eq!(::std::mem::size_of::<Foo_Bar>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo_Bar ) ));
- assert_eq! (::std::mem::align_of::<Foo_Bar>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo_Bar ) ));
- }
- impl Clone for Foo_Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo_Bar>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo_Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo_Bar>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo_Bar))
+ );
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- }
- impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
pub mod test {
#[allow(unused_imports)]
@@ -50,7 +56,7 @@ pub mod root {
/// I'm in a namespace, and thus I may be on a rust module, most of the time.
/// My documentation is pretty extensive, I guess.
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Baz {
/// This member is plain awesome, just amazing.
///
@@ -63,52 +69,66 @@ pub mod root {
}
#[test]
fn bindgen_test_layout_Baz() {
- assert_eq!(::std::mem::size_of::<Baz>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Baz ) ));
- assert_eq! (::std::mem::align_of::<Baz>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Baz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Baz ) ) . member as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Baz ) , "::" ,
- stringify ! ( member ) ));
- }
- impl Clone for Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Baz))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Baz)).member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Baz),
+ "::",
+ stringify!(member)
+ )
+ );
}
/// I'm in an inline namespace, and as such I shouldn't get generated inside
/// a rust module, except when the relevant option is specified. Also, this
/// comment shouldn't be misaligned.
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct InInlineNS {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_InInlineNS() {
- assert_eq!(::std::mem::size_of::<InInlineNS>() , 1usize , concat !
- ( "Size of: " , stringify ! ( InInlineNS ) ));
- assert_eq! (::std::mem::align_of::<InInlineNS>() , 1usize , concat
- ! ( "Alignment of " , stringify ! ( InInlineNS ) ));
+ assert_eq!(
+ ::std::mem::size_of::<InInlineNS>(),
+ 1usize,
+ concat!("Size of: ", stringify!(InInlineNS))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<InInlineNS>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(InInlineNS))
+ );
}
- impl Clone for InInlineNS {
- fn clone(&self) -> Self { *self }
- }
-
+
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bazz {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Bazz() {
- assert_eq!(::std::mem::size_of::<Bazz>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Bazz ) ));
- assert_eq! (::std::mem::align_of::<Bazz>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Bazz ) ));
- }
- impl Clone for Bazz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bazz>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Bazz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bazz>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Bazz))
+ );
}
}
}
diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs
index 6159f979..02c8714c 100644
--- a/tests/expectations/tests/complex.rs
+++ b/tests/expectations/tests/complex.rs
@@ -11,88 +11,124 @@ pub struct __BindgenComplex<T> {
pub im: T,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct TestDouble {
pub mMember: __BindgenComplex<f64>,
}
#[test]
fn bindgen_test_layout_TestDouble() {
- assert_eq!(::std::mem::size_of::<TestDouble>() , 16usize , concat ! (
- "Size of: " , stringify ! ( TestDouble ) ));
- assert_eq! (::std::mem::align_of::<TestDouble>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( TestDouble ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const TestDouble ) ) . mMember as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( TestDouble ) , "::" ,
- stringify ! ( mMember ) ));
-}
-impl Clone for TestDouble {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<TestDouble>(),
+ 16usize,
+ concat!("Size of: ", stringify!(TestDouble))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TestDouble>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(TestDouble))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const TestDouble)).mMember as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(TestDouble),
+ "::",
+ stringify!(mMember)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct TestDoublePtr {
pub mMember: *mut __BindgenComplex<f64>,
}
#[test]
fn bindgen_test_layout_TestDoublePtr() {
- assert_eq!(::std::mem::size_of::<TestDoublePtr>() , 8usize , concat ! (
- "Size of: " , stringify ! ( TestDoublePtr ) ));
- assert_eq! (::std::mem::align_of::<TestDoublePtr>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( TestDoublePtr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const TestDoublePtr ) ) . mMember as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( TestDoublePtr ) , "::"
- , stringify ! ( mMember ) ));
-}
-impl Clone for TestDoublePtr {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<TestDoublePtr>(),
+ 8usize,
+ concat!("Size of: ", stringify!(TestDoublePtr))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TestDoublePtr>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(TestDoublePtr))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const TestDoublePtr)).mMember as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(TestDoublePtr),
+ "::",
+ stringify!(mMember)
+ )
+ );
}
impl Default for TestDoublePtr {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct TestFloat {
pub mMember: __BindgenComplex<f32>,
}
#[test]
fn bindgen_test_layout_TestFloat() {
- assert_eq!(::std::mem::size_of::<TestFloat>() , 8usize , concat ! (
- "Size of: " , stringify ! ( TestFloat ) ));
- assert_eq! (::std::mem::align_of::<TestFloat>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( TestFloat ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const TestFloat ) ) . mMember as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( TestFloat ) , "::" ,
- stringify ! ( mMember ) ));
-}
-impl Clone for TestFloat {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<TestFloat>(),
+ 8usize,
+ concat!("Size of: ", stringify!(TestFloat))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TestFloat>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(TestFloat))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const TestFloat)).mMember as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(TestFloat),
+ "::",
+ stringify!(mMember)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct TestFloatPtr {
pub mMember: *mut __BindgenComplex<f32>,
}
#[test]
fn bindgen_test_layout_TestFloatPtr() {
- assert_eq!(::std::mem::size_of::<TestFloatPtr>() , 8usize , concat ! (
- "Size of: " , stringify ! ( TestFloatPtr ) ));
- assert_eq! (::std::mem::align_of::<TestFloatPtr>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( TestFloatPtr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const TestFloatPtr ) ) . mMember as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( TestFloatPtr ) , "::" ,
- stringify ! ( mMember ) ));
-}
-impl Clone for TestFloatPtr {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<TestFloatPtr>(),
+ 8usize,
+ concat!("Size of: ", stringify!(TestFloatPtr))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TestFloatPtr>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(TestFloatPtr))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const TestFloatPtr)).mMember as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(TestFloatPtr),
+ "::",
+ stringify!(mMember)
+ )
+ );
}
impl Default for TestFloatPtr {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/complex_global.rs b/tests/expectations/tests/complex_global.rs
index 83135220..defdbe68 100644
--- a/tests/expectations/tests/complex_global.rs
+++ b/tests/expectations/tests/complex_global.rs
@@ -11,14 +11,14 @@ pub struct __BindgenComplex<T> {
pub im: T,
}
extern "C" {
- #[link_name = "globalValueFloat"]
+ #[link_name = "\u{1}globalValueFloat"]
pub static mut globalValueFloat: __BindgenComplex<f32>;
}
extern "C" {
- #[link_name = "globalValueDouble"]
+ #[link_name = "\u{1}globalValueDouble"]
pub static mut globalValueDouble: __BindgenComplex<f64>;
}
extern "C" {
- #[link_name = "globalValueLongDouble"]
+ #[link_name = "\u{1}globalValueLongDouble"]
pub static mut globalValueLongDouble: __BindgenComplex<f64>;
}
diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs
index 98c6240f..539c8916 100644
--- a/tests/expectations/tests/const_enum_unnamed.rs
+++ b/tests/expectations/tests/const_enum_unnamed.rs
@@ -8,23 +8,31 @@ pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR;
pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _bindgen_ty_1 { FOO_BAR = 0, FOO_BAZ = 1, }
+pub enum _bindgen_ty_1 {
+ FOO_BAR = 0,
+ FOO_BAZ = 1,
+}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, }
+pub enum Foo__bindgen_ty_1 {
+ FOO_BAR = 10,
+}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/const_tparam.rs b/tests/expectations/tests/const_tparam.rs
index 9c101ec6..218abbdb 100644
--- a/tests/expectations/tests/const_tparam.rs
+++ b/tests/expectations/tests/const_tparam.rs
@@ -11,6 +11,8 @@ pub struct C<T> {
pub bar: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for C<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for C<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs
index af13e079..3b37daf3 100644
--- a/tests/expectations/tests/constify-all-enums.rs
+++ b/tests/expectations/tests/constify-all-enums.rs
@@ -9,7 +9,7 @@ pub const foo_SHOULD_BE: foo = 1;
pub const foo_A_CONSTANT: foo = 2;
pub type foo = ::std::os::raw::c_uint;
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct bar {
pub this_should_work: foo,
}
@@ -36,11 +36,6 @@ fn bindgen_test_layout_bar() {
)
);
}
-impl Clone for bar {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for bar {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/constify-enum.rs b/tests/expectations/tests/constify-enum.rs
index 1d04210b..78644ae4 100644
--- a/tests/expectations/tests/constify-enum.rs
+++ b/tests/expectations/tests/constify-enum.rs
@@ -4,8 +4,7 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue:
- nsCSSPropertyID =
+pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSPropertyID =
nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue;
pub const nsCSSPropertyID_eCSSProperty_COUNT: nsCSSPropertyID =
nsCSSPropertyID::eCSSPropertyAlias_aa;
diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs
index bfe33c6b..6c56e2ec 100644
--- a/tests/expectations/tests/constify-module-enums-basic.rs
+++ b/tests/expectations/tests/constify-module-enums-basic.rs
@@ -13,7 +13,7 @@ pub mod foo {
pub use self::foo::Type as foo_alias1;
pub use self::foo_alias1 as foo_alias2;
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct bar {
pub this_should_work: foo::Type,
}
@@ -40,11 +40,6 @@ fn bindgen_test_layout_bar() {
)
);
}
-impl Clone for bar {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for bar {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs
index 4db009be..b09f837d 100644
--- a/tests/expectations/tests/constify-module-enums-namespace.rs
+++ b/tests/expectations/tests/constify-module-enums-namespace.rs
@@ -25,27 +25,37 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::super::root;
#[repr(C)]
- #[derive(Debug, Copy)]
+ #[derive(Debug, Copy, Clone)]
pub struct bar {
pub this_should_work: root::ns1::ns2::foo::Type,
}
#[test]
fn bindgen_test_layout_bar() {
- assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( bar ) ));
- assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . this_should_work as
- * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) ,
- "::" , stringify ! ( this_should_work ) ));
- }
- impl Clone for bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).this_should_work as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(this_should_work)
+ )
+ );
}
impl Default for bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
}
}
diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs
index 9b5fd7b8..1f2b4b2f 100644
--- a/tests/expectations/tests/constify-module-enums-shadow-name.rs
+++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs
@@ -12,25 +12,35 @@ pub mod foo {
pub const Type__: Type = 3;
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct bar {
pub member: foo::Type,
}
#[test]
fn bindgen_test_layout_bar() {
- assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( bar ) ));
- assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member ) ));
-}
-impl Clone for bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member)
+ )
+ );
}
impl Default for bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs
index 75c952d7..0387ddd0 100644
--- a/tests/expectations/tests/constify-module-enums-simple-alias.rs
+++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs
@@ -14,7 +14,7 @@ pub use self::Foo::Type as Foo_alias1;
pub use self::Foo_alias1 as Foo_alias2;
pub use self::Foo_alias2 as Foo_alias3;
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Bar {
pub baz1: Foo::Type,
pub baz2: Foo_alias1,
@@ -118,11 +118,6 @@ fn bindgen_test_layout_Bar() {
)
);
}
-impl Clone for Bar {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for Bar {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
index 4f8d46c5..7fb4606f 100644
--- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
+++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
@@ -10,31 +10,46 @@ pub mod one_Foo {
pub const Variant2: Type = 1;
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Bar {
pub baz1: one_Foo::Type,
pub baz2: *mut one_Foo::Type,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 16usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . baz1 as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( baz1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . baz2 as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( baz2 ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 16usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).baz1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(baz1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).baz2 as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(baz2)
+ )
+ );
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs
index 4eb100c4..cc1f3d4c 100644
--- a/tests/expectations/tests/constify-module-enums-types.rs
+++ b/tests/expectations/tests/constify-module-enums-types.rs
@@ -37,7 +37,7 @@ pub use self::anon_enum::Type as anon_enum_alias1;
pub use self::anon_enum_alias1 as anon_enum_alias2;
pub use self::anon_enum_alias2 as anon_enum_alias3;
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct bar {
pub member1: foo::Type,
pub member2: foo_alias1,
@@ -52,89 +52,154 @@ pub struct bar {
}
#[test]
fn bindgen_test_layout_bar() {
- assert_eq!(::std::mem::size_of::<bar>() , 48usize , concat ! (
- "Size of: " , stringify ! ( bar ) ));
- assert_eq! (::std::mem::align_of::<bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member1 as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member2 as * const _ as usize }
- , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member3 as * const _ as usize }
- , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member3 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member4 as * const _ as usize }
- , 12usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member4 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member5 as * const _ as usize }
- , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member5 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member6 as * const _ as usize }
- , 24usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member6 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member7 as * const _ as usize }
- , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member7 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member8 as * const _ as usize }
- , 36usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member8 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member9 as * const _ as usize }
- , 40usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member9 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . member10 as * const _ as usize
- } , 44usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( member10 ) ));
-}
-impl Clone for bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<bar>(),
+ 48usize,
+ concat!("Size of: ", stringify!(bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member2 as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member3 as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member3)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member4 as *const _ as usize },
+ 12usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member4)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member5 as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member5)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member6 as *const _ as usize },
+ 24usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member6)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member7 as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member7)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member8 as *const _ as usize },
+ 36usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member8)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member9 as *const _ as usize },
+ 40usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member9)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).member10 as *const _ as usize },
+ 44usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(member10)
+ )
+ );
}
impl Default for bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Baz {
pub member1: ns2_Foo::Type,
}
#[test]
fn bindgen_test_layout_Baz() {
- assert_eq!(::std::mem::size_of::<Baz>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Baz ) ));
- assert_eq! (::std::mem::align_of::<Baz>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Baz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Baz ) ) . member1 as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Baz ) , "::" ,
- stringify ! ( member1 ) ));
-}
-impl Clone for Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Baz))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Baz)).member1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Baz),
+ "::",
+ stringify!(member1)
+ )
+ );
}
impl Default for Baz {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub mod one_Foo {
pub type Type = ::std::os::raw::c_int;
@@ -142,37 +207,53 @@ pub mod one_Foo {
pub const Variant2: Type = 1;
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Bar {
pub baz: *mut one_Foo::Type,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( baz ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(baz)
+ )
+ );
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_Z5func13fooPS_PS0_"]
- pub fn func1(arg1: foo::Type, arg2: *mut foo::Type,
- arg3: *mut *mut foo::Type) -> *mut foo::Type;
+ #[link_name = "\u{1}_Z5func13fooPS_PS0_"]
+ pub fn func1(
+ arg1: foo::Type,
+ arg2: *mut foo::Type,
+ arg3: *mut *mut foo::Type,
+ ) -> *mut foo::Type;
}
extern "C" {
- #[link_name = "_Z5func23fooPS_PS0_"]
- pub fn func2(arg1: foo_alias1, arg2: *mut foo_alias1,
- arg3: *mut *mut foo_alias1) -> *mut foo_alias1;
+ #[link_name = "\u{1}_Z5func23fooPS_PS0_"]
+ pub fn func2(
+ arg1: foo_alias1,
+ arg2: *mut foo_alias1,
+ arg3: *mut *mut foo_alias1,
+ ) -> *mut foo_alias1;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -180,14 +261,16 @@ pub struct Thing<T> {
pub thing: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Thing<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Thing<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_Z5func35ThingI3fooE"]
+ #[link_name = "\u{1}_Z5func35ThingI3fooE"]
pub fn func3(arg1: Thing<foo::Type>) -> foo::Type;
}
extern "C" {
- #[link_name = "_Z5func45ThingIS_I3fooEE"]
+ #[link_name = "\u{1}_Z5func45ThingIS_I3fooEE"]
pub fn func4(arg1: Thing<Thing<foo::Type>>) -> foo::Type;
}
diff --git a/tests/expectations/tests/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs
index 7ce4b9b3..73360248 100644
--- a/tests/expectations/tests/constructor-tp.rs
+++ b/tests/expectations/tests/constructor-tp.rs
@@ -10,24 +10,27 @@ pub struct Foo {
pub _address: u8,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
}
extern "C" {
- #[link_name = "_ZN3BarC1Ev"]
+ #[link_name = "\u{1}_ZN3BarC1Ev"]
pub fn Bar_Bar(this: *mut Bar);
}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
-}
impl Bar {
#[inline]
pub unsafe fn new() -> Self {
diff --git a/tests/expectations/tests/constructors.rs b/tests/expectations/tests/constructors.rs
index c267ce1c..b20e3f44 100644
--- a/tests/expectations/tests/constructors.rs
+++ b/tests/expectations/tests/constructors.rs
@@ -5,29 +5,31 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct TestOverload {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_TestOverload() {
- assert_eq!(::std::mem::size_of::<TestOverload>() , 1usize , concat ! (
- "Size of: " , stringify ! ( TestOverload ) ));
- assert_eq! (::std::mem::align_of::<TestOverload>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( TestOverload ) ));
+ assert_eq!(
+ ::std::mem::size_of::<TestOverload>(),
+ 1usize,
+ concat!("Size of: ", stringify!(TestOverload))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TestOverload>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(TestOverload))
+ );
}
extern "C" {
- #[link_name = "_ZN12TestOverloadC1Ei"]
- pub fn TestOverload_TestOverload(this: *mut TestOverload,
- arg1: ::std::os::raw::c_int);
+ #[link_name = "\u{1}_ZN12TestOverloadC1Ei"]
+ pub fn TestOverload_TestOverload(this: *mut TestOverload, arg1: ::std::os::raw::c_int);
}
extern "C" {
- #[link_name = "_ZN12TestOverloadC1Ed"]
+ #[link_name = "\u{1}_ZN12TestOverloadC1Ed"]
pub fn TestOverload_TestOverload1(this: *mut TestOverload, arg1: f64);
}
-impl Clone for TestOverload {
- fn clone(&self) -> Self { *self }
-}
impl TestOverload {
#[inline]
pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self {
@@ -43,24 +45,27 @@ impl TestOverload {
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct TestPublicNoArgs {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_TestPublicNoArgs() {
- assert_eq!(::std::mem::size_of::<TestPublicNoArgs>() , 1usize , concat ! (
- "Size of: " , stringify ! ( TestPublicNoArgs ) ));
- assert_eq! (::std::mem::align_of::<TestPublicNoArgs>() , 1usize , concat !
- ( "Alignment of " , stringify ! ( TestPublicNoArgs ) ));
+ assert_eq!(
+ ::std::mem::size_of::<TestPublicNoArgs>(),
+ 1usize,
+ concat!("Size of: ", stringify!(TestPublicNoArgs))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<TestPublicNoArgs>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(TestPublicNoArgs))
+ );
}
extern "C" {
- #[link_name = "_ZN16TestPublicNoArgsC1Ev"]
+ #[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"]
pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs);
}
-impl Clone for TestPublicNoArgs {
- fn clone(&self) -> Self { *self }
-}
impl TestPublicNoArgs {
#[inline]
pub unsafe fn new() -> Self {
diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs
new file mode 100644
index 00000000..b567bbbd
--- /dev/null
+++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs
@@ -0,0 +1,97 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+
+/// This should get an `_address` byte.
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Empty {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_Empty() {
+ assert_eq!(
+ ::std::mem::size_of::<Empty>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Empty))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Empty>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Empty))
+ );
+}
+/// This should not get an `_address` byte, so `sizeof(Inherits)` should be
+/// `1`.
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Inherits {
+ pub b: bool,
+}
+#[test]
+fn bindgen_test_layout_Inherits() {
+ assert_eq!(
+ ::std::mem::size_of::<Inherits>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Inherits))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Inherits>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Inherits))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Inherits)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Inherits),
+ "::",
+ stringify!(b)
+ )
+ );
+}
+/// This should not get an `_address` byte, but contains `Empty` which *does* get
+/// one, so `sizeof(Contains)` should be `1 + 1`.
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Contains {
+ pub empty: Empty,
+ pub b: bool,
+}
+#[test]
+fn bindgen_test_layout_Contains() {
+ assert_eq!(
+ ::std::mem::size_of::<Contains>(),
+ 2usize,
+ concat!("Size of: ", stringify!(Contains))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Contains>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Contains))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Contains)).empty as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Contains),
+ "::",
+ stringify!(empty)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Contains)).b as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Contains),
+ "::",
+ stringify!(b)
+ )
+ );
+}
diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs
index 08570f16..b471386a 100644
--- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs
+++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs
@@ -7,7 +7,7 @@
pub type mbedtls_mpi_uint = ::std::os::raw::c_uint;
/// \brief MPI structure
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct mbedtls_mpi {
/// < integer sign
pub s: ::std::os::raw::c_int,
@@ -18,29 +18,49 @@ pub struct mbedtls_mpi {
}
#[test]
fn bindgen_test_layout_mbedtls_mpi() {
- assert_eq!(::std::mem::size_of::<mbedtls_mpi>() , 24usize , concat ! (
- "Size of: " , stringify ! ( mbedtls_mpi ) ));
- assert_eq! (::std::mem::align_of::<mbedtls_mpi>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( mbedtls_mpi ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const mbedtls_mpi ) ) . s as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( mbedtls_mpi ) , "::" ,
- stringify ! ( s ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const mbedtls_mpi ) ) . n as * const _ as usize
- } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( mbedtls_mpi ) , "::" ,
- stringify ! ( n ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const mbedtls_mpi ) ) . p as * const _ as usize
- } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( mbedtls_mpi ) , "::" ,
- stringify ! ( p ) ));
-}
-impl Clone for mbedtls_mpi {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<mbedtls_mpi>(),
+ 24usize,
+ concat!("Size of: ", stringify!(mbedtls_mpi))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mbedtls_mpi>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(mbedtls_mpi))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const mbedtls_mpi)).s as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(mbedtls_mpi),
+ "::",
+ stringify!(s)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const mbedtls_mpi)).n as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(mbedtls_mpi),
+ "::",
+ stringify!(n)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const mbedtls_mpi)).p as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(mbedtls_mpi),
+ "::",
+ stringify!(p)
+ )
+ );
}
impl Default for mbedtls_mpi {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs
index 906da262..87554a2c 100644
--- a/tests/expectations/tests/convert-floats.rs
+++ b/tests/expectations/tests/convert-floats.rs
@@ -11,7 +11,7 @@ pub struct __BindgenComplex<T> {
pub im: T,
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct foo {
pub bar: ::std::os::raw::c_float,
pub baz: ::std::os::raw::c_float,
@@ -22,44 +22,79 @@ pub struct foo {
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 48usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . baz as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( baz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bazz as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bazz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bazzz as * const _ as usize } ,
- 16usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bazzz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . complexFloat as * const _ as
- usize } , 24usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( complexFloat ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . complexDouble as * const _ as
- usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( complexDouble ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 48usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).baz as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(baz)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bazz as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bazz)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bazzz as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bazzz)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).complexFloat as *const _ as usize },
+ 24usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(complexFloat)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).complexDouble as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(complexDouble)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/cpp-empty-layout.rs b/tests/expectations/tests/cpp-empty-layout.rs
index c894b95c..36cae722 100644
--- a/tests/expectations/tests/cpp-empty-layout.rs
+++ b/tests/expectations/tests/cpp-empty-layout.rs
@@ -5,17 +5,20 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs
index f2b1dbd8..c56cceb2 100644
--- a/tests/expectations/tests/crtp.rs
+++ b/tests/expectations/tests/crtp.rs
@@ -10,19 +10,22 @@ pub struct Base {
pub _address: u8,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Derived {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Derived() {
- assert_eq!(::std::mem::size_of::<Derived>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Derived ) ));
- assert_eq! (::std::mem::align_of::<Derived>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Derived ) ));
-}
-impl Clone for Derived {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Derived>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Derived))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Derived>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Derived))
+ );
}
#[repr(C)]
#[derive(Debug, Default)]
@@ -36,30 +39,47 @@ pub struct DerivedFromBaseWithDestructor {
}
#[test]
fn bindgen_test_layout_DerivedFromBaseWithDestructor() {
- assert_eq!(::std::mem::size_of::<DerivedFromBaseWithDestructor>() , 1usize
- , concat ! (
- "Size of: " , stringify ! ( DerivedFromBaseWithDestructor ) ));
- assert_eq! (::std::mem::align_of::<DerivedFromBaseWithDestructor>() ,
- 1usize , concat ! (
- "Alignment of " , stringify ! ( DerivedFromBaseWithDestructor
- ) ));
+ assert_eq!(
+ ::std::mem::size_of::<DerivedFromBaseWithDestructor>(),
+ 1usize,
+ concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DerivedFromBaseWithDestructor>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor))
+ );
}
#[test]
fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<Base>() , 1usize , concat ! (
- "Size of template specialization: " , stringify ! ( Base ) ));
- assert_eq!(::std::mem::align_of::<Base>() , 1usize , concat ! (
- "Alignment of template specialization: " , stringify ! ( Base )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<Base>(),
+ 1usize,
+ concat!("Size of template specialization: ", stringify!(Base))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Base>(),
+ 1usize,
+ concat!("Alignment of template specialization: ", stringify!(Base))
+ );
}
#[test]
-fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat !
- (
- "Size of template specialization: " , stringify ! (
- BaseWithDestructor ) ));
- assert_eq!(::std::mem::align_of::<BaseWithDestructor>() , 1usize , concat
- ! (
- "Alignment of template specialization: " , stringify ! (
- BaseWithDestructor ) ));
+fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation(
+) {
+ assert_eq!(
+ ::std::mem::size_of::<BaseWithDestructor>(),
+ 1usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(BaseWithDestructor)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BaseWithDestructor>(),
+ 1usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(BaseWithDestructor)
+ )
+ );
}
diff --git a/tests/expectations/tests/decl_extern_int_twice.rs b/tests/expectations/tests/decl_extern_int_twice.rs
index a7954390..99545758 100644
--- a/tests/expectations/tests/decl_extern_int_twice.rs
+++ b/tests/expectations/tests/decl_extern_int_twice.rs
@@ -5,6 +5,6 @@
extern "C" {
- #[link_name = "foo"]
+ #[link_name = "\u{1}foo"]
pub static mut foo: ::std::os::raw::c_int;
}
diff --git a/tests/expectations/tests/decl_ptr_to_array.rs b/tests/expectations/tests/decl_ptr_to_array.rs
index 4045a121..6d6eeb4b 100644
--- a/tests/expectations/tests/decl_ptr_to_array.rs
+++ b/tests/expectations/tests/decl_ptr_to_array.rs
@@ -5,6 +5,6 @@
extern "C" {
- #[link_name = "foo"]
+ #[link_name = "\u{1}foo"]
pub static mut foo: *mut [::std::os::raw::c_int; 1usize];
}
diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs
index 8dae0c90..8d4ba3dd 100644
--- a/tests/expectations/tests/default-template-parameter.rs
+++ b/tests/expectations/tests/default-template-parameter.rs
@@ -37,6 +37,6 @@ fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() {
);
}
extern "C" {
- #[link_name = "_ZL3bar"]
+ #[link_name = "\u{1}_ZL3bar"]
pub static mut bar: Foo<bool, ::std::os::raw::c_int>;
}
diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs
new file mode 100644
index 00000000..62050886
--- /dev/null
+++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs
@@ -0,0 +1,131 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+
+/// Because this struct have array larger than 32 items
+/// and --with-derive-partialeq --impl-partialeq --impl-debug is provided,
+/// this struct should manually implement `Debug` and `PartialEq`.
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct Foo {
+ pub large: [::std::os::raw::c_int; 33usize],
+ pub _bitfield_1: [u8; 2usize],
+ pub __bindgen_padding_0: u16,
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 136usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).large as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(large)
+ )
+ );
+}
+extern "C" {
+ #[link_name = "\u{1}_ZN3Foo4typeEv"]
+ pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char;
+}
+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" {
+ #[link_name = "\u{1}_ZN3Foo8set_typeEc"]
+ pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char);
+}
+impl Default for Foo {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::fmt::Debug for Foo {
+ fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ write!(
+ f,
+ "Foo {{ large: [{}], type_ : {:?}, }}",
+ self.large
+ .iter()
+ .enumerate()
+ .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v))
+ .collect::<String>(),
+ self.type__bindgen_bitfield()
+ )
+ }
+}
+impl ::std::cmp::PartialEq for Foo {
+ fn eq(&self, other: &Foo) -> bool {
+ &self.large[..] == &other.large[..]
+ && self.type__bindgen_bitfield() == other.type__bindgen_bitfield()
+ }
+}
+impl Foo {
+ #[inline]
+ pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char {
+ let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u16 as *mut u8,
+ ::std::mem::size_of::<u16>(),
+ )
+ };
+ let mask = 0x7 as u16;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u8) }
+ }
+ #[inline]
+ pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) {
+ let mask = 0x7 as u16;
+ let val = val as u8 as u16;
+ let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u16 as *mut u8,
+ ::std::mem::size_of::<u16>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u16>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(type__bindgen_bitfield: ::std::os::raw::c_char) -> u16 {
+ (0 | ((type__bindgen_bitfield as u8 as u16) << 0usize) & (0x7 as u16))
+ }
+ #[inline]
+ pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char {
+ Foo_type(self)
+ }
+ #[inline]
+ pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) {
+ Foo_set_type_(self, c)
+ }
+ #[inline]
+ pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) {
+ Foo_set_type(self, c)
+ }
+}
diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs
new file mode 100644
index 00000000..356d93e3
--- /dev/null
+++ b/tests/expectations/tests/derive-clone.rs
@@ -0,0 +1,41 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+
+/// This struct should derive `Clone`.
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct ShouldDeriveClone {
+ pub large: [::std::os::raw::c_int; 33usize],
+}
+#[test]
+fn bindgen_test_layout_ShouldDeriveClone() {
+ assert_eq!(
+ ::std::mem::size_of::<ShouldDeriveClone>(),
+ 132usize,
+ concat!("Size of: ", stringify!(ShouldDeriveClone))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ShouldDeriveClone>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ShouldDeriveClone))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ShouldDeriveClone)).large as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ShouldDeriveClone),
+ "::",
+ stringify!(large)
+ )
+ );
+}
+impl Default for ShouldDeriveClone {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs
new file mode 100644
index 00000000..2ead68ee
--- /dev/null
+++ b/tests/expectations/tests/derive-clone_1_0.rs
@@ -0,0 +1,47 @@
+/* automatically generated by rust-bindgen */
+
+
+#![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() {
+ assert_eq!(
+ ::std::mem::size_of::<ShouldImplClone>(),
+ 132usize,
+ concat!("Size of: ", stringify!(ShouldImplClone))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ShouldImplClone>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ShouldImplClone))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ShouldImplClone)).large as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ShouldImplClone),
+ "::",
+ stringify!(large)
+ )
+ );
+}
+impl Clone for ShouldImplClone {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+impl Default for ShouldImplClone {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs
index 47ec570b..d664a4ba 100644
--- a/tests/expectations/tests/derive-debug-bitfield.rs
+++ b/tests/expectations/tests/derive-debug-bitfield.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct C {
pub _bitfield_1: u8,
pub large_array: [::std::os::raw::c_int; 50usize],
@@ -33,11 +33,6 @@ fn bindgen_test_layout_C() {
)
);
}
-impl Clone for C {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for C {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -69,13 +64,13 @@ impl C {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_a(&mut self, val: bool) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -105,13 +100,13 @@ impl C {
::std::mem::size_of::<u8>(),
)
};
- let mask = 254u64 as u8;
+ let mask = 0xfe as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_b(&mut self, val: bool) {
- let mask = 254u64 as u8;
+ let mask = 0xfe as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -133,7 +128,7 @@ impl C {
}
#[inline]
pub fn new_bitfield_1(a: bool, b: bool) -> u8 {
- ((0 | ((a as u8 as u8) << 0usize) & (1u64 as u8)) |
- ((b as u8 as u8) << 1usize) & (254u64 as u8))
+ ((0 | ((a as u8 as u8) << 0usize) & (0x1 as u8))
+ | ((b as u8 as u8) << 1usize) & (0xfe as u8))
}
}
diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs
index 03cafe97..01ffe206 100644
--- a/tests/expectations/tests/derive-debug-function-pointer.rs
+++ b/tests/expectations/tests/derive-debug-function-pointer.rs
@@ -5,43 +5,61 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct Nice {
pub pointer: Nice_Function,
pub large_array: [::std::os::raw::c_int; 34usize],
}
-pub type Nice_Function =
- ::std::option::Option<unsafe extern "C" fn(data: ::std::os::raw::c_int)>;
+pub type Nice_Function = ::std::option::Option<unsafe extern "C" fn(data: ::std::os::raw::c_int)>;
#[test]
fn bindgen_test_layout_Nice() {
- assert_eq!(::std::mem::size_of::<Nice>() , 144usize , concat ! (
- "Size of: " , stringify ! ( Nice ) ));
- assert_eq! (::std::mem::align_of::<Nice>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Nice ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Nice ) ) . pointer as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Nice ) , "::" ,
- stringify ! ( pointer ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Nice ) ) . large_array as * const _ as
- usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( Nice ) , "::" ,
- stringify ! ( large_array ) ));
-}
-impl Clone for Nice {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Nice>(),
+ 144usize,
+ concat!("Size of: ", stringify!(Nice))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Nice>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Nice))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Nice)).pointer as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Nice),
+ "::",
+ stringify!(pointer)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Nice)).large_array as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Nice),
+ "::",
+ stringify!(large_array)
+ )
+ );
}
impl Default for Nice {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl ::std::fmt::Debug for Nice {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
- write!(f , "Nice {{ pointer: {:?}, large_array: [{}] }}" , self .
- pointer , self . large_array . iter ( ) . enumerate ( ) . map
- (
- | ( i , v ) | format ! (
- "{}{:?}" , if i > 0 { ", " } else { "" } , v ) ) . collect :: <
- String > ( ))
+ write!(
+ f,
+ "Nice {{ pointer: {:?}, large_array: [{}] }}",
+ self.pointer,
+ self.large_array
+ .iter()
+ .enumerate()
+ .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v))
+ .collect::<String>()
+ )
}
}
diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs
index e5529255..5bc6e20d 100644
--- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs
+++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs
@@ -10,21 +10,34 @@ pub struct Instance {
}
#[test]
fn bindgen_test_layout_Instance() {
- assert_eq!(::std::mem::size_of::<Instance>() , 200usize , concat ! (
- "Size of: " , stringify ! ( Instance ) ));
- assert_eq! (::std::mem::align_of::<Instance>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Instance ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Instance ) ) . val as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Instance ) , "::" ,
- stringify ! ( val ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Instance>(),
+ 200usize,
+ concat!("Size of: ", stringify!(Instance))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Instance>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Instance))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Instance)).val as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Instance),
+ "::",
+ stringify!(val)
+ )
+ );
}
impl Default for Instance {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl ::std::fmt::Debug for Instance {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
- write!(f , "Instance {{ val: opaque }}")
+ write!(f, "Instance {{ val: opaque }}")
}
}
diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs
index 267aca11..29c1d791 100644
--- a/tests/expectations/tests/derive-debug-opaque.rs
+++ b/tests/expectations/tests/derive-debug-opaque.rs
@@ -10,17 +10,25 @@ pub struct Opaque {
}
#[test]
fn bindgen_test_layout_Opaque() {
- assert_eq!(::std::mem::size_of::<Opaque>() , 164usize , concat ! (
- "Size of: " , stringify ! ( Opaque ) ));
- assert_eq! (::std::mem::align_of::<Opaque>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Opaque ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Opaque>(),
+ 164usize,
+ concat!("Size of: ", stringify!(Opaque))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Opaque>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Opaque))
+ );
}
impl Default for Opaque {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl ::std::fmt::Debug for Opaque {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
- write!(f , "Opaque {{ opaque }}")
+ write!(f, "Opaque {{ opaque }}")
}
}
#[repr(C)]
@@ -29,21 +37,34 @@ pub struct OpaqueUser {
}
#[test]
fn bindgen_test_layout_OpaqueUser() {
- assert_eq!(::std::mem::size_of::<OpaqueUser>() , 164usize , concat ! (
- "Size of: " , stringify ! ( OpaqueUser ) ));
- assert_eq! (::std::mem::align_of::<OpaqueUser>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( OpaqueUser ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const OpaqueUser ) ) . opaque as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( OpaqueUser ) , "::" ,
- stringify ! ( opaque ) ));
+ assert_eq!(
+ ::std::mem::size_of::<OpaqueUser>(),
+ 164usize,
+ concat!("Size of: ", stringify!(OpaqueUser))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<OpaqueUser>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(OpaqueUser))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const OpaqueUser)).opaque as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(OpaqueUser),
+ "::",
+ stringify!(opaque)
+ )
+ );
}
impl Default for OpaqueUser {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl ::std::fmt::Debug for OpaqueUser {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
- write!(f , "OpaqueUser {{ opaque: {:?} }}" , self . opaque)
+ write!(f, "OpaqueUser {{ opaque: {:?} }}", self.opaque)
}
}
diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs
index ac479296..382d9063 100644
--- a/tests/expectations/tests/derive-fn-ptr.rs
+++ b/tests/expectations/tests/derive-fn-ptr.rs
@@ -4,79 +4,105 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-pub type my_fun_t =
- ::std::option::Option<unsafe extern "C" fn(arg1: ::std::os::raw::c_int,
- arg2: ::std::os::raw::c_int,
- arg3: ::std::os::raw::c_int,
- arg4: ::std::os::raw::c_int,
- arg5: ::std::os::raw::c_int,
- arg6: ::std::os::raw::c_int,
- arg7: ::std::os::raw::c_int,
- arg8: ::std::os::raw::c_int,
- arg9: ::std::os::raw::c_int,
- arg10: ::std::os::raw::c_int,
- arg11: ::std::os::raw::c_int,
- arg12: ::std::os::raw::c_int,
- arg13: ::std::os::raw::c_int,
- arg14: ::std::os::raw::c_int,
- arg15: ::std::os::raw::c_int,
- arg16: ::std::os::raw::c_int)>;
+pub type my_fun_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ arg1: ::std::os::raw::c_int,
+ arg2: ::std::os::raw::c_int,
+ arg3: ::std::os::raw::c_int,
+ arg4: ::std::os::raw::c_int,
+ arg5: ::std::os::raw::c_int,
+ arg6: ::std::os::raw::c_int,
+ arg7: ::std::os::raw::c_int,
+ arg8: ::std::os::raw::c_int,
+ arg9: ::std::os::raw::c_int,
+ arg10: ::std::os::raw::c_int,
+ arg11: ::std::os::raw::c_int,
+ arg12: ::std::os::raw::c_int,
+ arg13: ::std::os::raw::c_int,
+ arg14: ::std::os::raw::c_int,
+ arg15: ::std::os::raw::c_int,
+ arg16: ::std::os::raw::c_int,
+ ),
+>;
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct Foo {
pub callback: my_fun_t,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . callback as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( callback ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).callback as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(callback)
+ )
+ );
}
impl Default for Foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-pub type my_fun2_t =
- ::std::option::Option<unsafe extern "C" fn(arg1: ::std::os::raw::c_int,
- arg2: ::std::os::raw::c_int,
- arg3: ::std::os::raw::c_int,
- arg4: ::std::os::raw::c_int,
- arg5: ::std::os::raw::c_int,
- arg6: ::std::os::raw::c_int,
- arg7: ::std::os::raw::c_int,
- arg8: ::std::os::raw::c_int,
- arg9: ::std::os::raw::c_int,
- arg10: ::std::os::raw::c_int,
- arg11: ::std::os::raw::c_int,
- arg12: ::std::os::raw::c_int)>;
+pub type my_fun2_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ arg1: ::std::os::raw::c_int,
+ arg2: ::std::os::raw::c_int,
+ arg3: ::std::os::raw::c_int,
+ arg4: ::std::os::raw::c_int,
+ arg5: ::std::os::raw::c_int,
+ arg6: ::std::os::raw::c_int,
+ arg7: ::std::os::raw::c_int,
+ arg8: ::std::os::raw::c_int,
+ arg9: ::std::os::raw::c_int,
+ arg10: ::std::os::raw::c_int,
+ arg11: ::std::os::raw::c_int,
+ arg12: ::std::os::raw::c_int,
+ ),
+>;
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Bar {
pub callback: my_fun2_t,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . callback as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( callback ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).callback as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(callback)
+ )
+ );
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
index 332c1129..b4f93f73 100644
--- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
@@ -5,14 +5,14 @@
-/// A struct containing a struct containing a float that cannot derive hash/eq but can derive partial eq.
+/// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
pub struct foo {
pub bar: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
pub struct foo__bindgen_ty_1 {
pub a: f32,
pub b: f32,
@@ -50,11 +50,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() {
)
);
}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self {
- *self
- }
-}
#[test]
fn bindgen_test_layout_foo() {
assert_eq!(
@@ -78,8 +73,3 @@ fn bindgen_test_layout_foo() {
)
);
}
-impl Clone for foo {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs
index 43075796..d736c114 100644
--- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs
@@ -5,9 +5,9 @@
-/// A struct containing an array of floats that cannot derive hash/eq but can derive partialeq.
+/// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
#[repr(C)]
-#[derive(Debug, Default, Copy, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
pub struct foo {
pub bar: [f32; 3usize],
}
@@ -34,8 +34,3 @@ fn bindgen_test_layout_foo() {
)
);
}
-impl Clone for foo {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs
new file mode 100644
index 00000000..a2179f41
--- /dev/null
+++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs
@@ -0,0 +1,121 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Default)]
+pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
+impl<T> __IncompleteArrayField<T> {
+ #[inline]
+ pub fn new() -> Self {
+ __IncompleteArrayField(::std::marker::PhantomData)
+ }
+ #[inline]
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
+ #[inline]
+ pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
+ ::std::mem::transmute(self)
+ }
+ #[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<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__IncompleteArrayField")
+ }
+}
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
+ #[inline]
+ fn clone(&self) -> Self {
+ Self::new()
+ }
+}
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct test {
+ pub a: ::std::os::raw::c_int,
+ pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_test() {
+ assert_eq!(
+ ::std::mem::size_of::<test>(),
+ 4usize,
+ concat!("Size of: ", stringify!(test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<test>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(test))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const test)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(test),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const test)).zero_length_array as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(test),
+ "::",
+ stringify!(zero_length_array)
+ )
+ );
+}
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct test2 {
+ pub a: ::std::os::raw::c_int,
+ pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_test2() {
+ assert_eq!(
+ ::std::mem::size_of::<test2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(test2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<test2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(test2))
+ );
+}
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct test3 {
+ pub a: ::std::os::raw::c_int,
+ pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>,
+ pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_test3() {
+ assert_eq!(
+ ::std::mem::size_of::<test3>(),
+ 4usize,
+ concat!("Size of: ", stringify!(test3))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<test3>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(test3))
+ );
+}
diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs
index 28aa1e25..7ff50fcf 100644
--- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs
@@ -5,9 +5,9 @@
-/// Pointers can derive hash/PartialEq/Eq
+/// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct ConstPtrMutObj {
pub bar: *const ::std::os::raw::c_int,
}
@@ -34,18 +34,13 @@ fn bindgen_test_layout_ConstPtrMutObj() {
)
);
}
-impl Clone for ConstPtrMutObj {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for ConstPtrMutObj {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct MutPtrMutObj {
pub bar: *mut ::std::os::raw::c_int,
}
@@ -72,18 +67,13 @@ fn bindgen_test_layout_MutPtrMutObj() {
)
);
}
-impl Clone for MutPtrMutObj {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for MutPtrMutObj {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct MutPtrConstObj {
pub bar: *const ::std::os::raw::c_int,
}
@@ -110,18 +100,13 @@ fn bindgen_test_layout_MutPtrConstObj() {
)
);
}
-impl Clone for MutPtrConstObj {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for MutPtrConstObj {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct ConstPtrConstObj {
pub bar: *const ::std::os::raw::c_int,
}
@@ -148,11 +133,6 @@ fn bindgen_test_layout_ConstPtrConstObj() {
)
);
}
-impl Clone for ConstPtrConstObj {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for ConstPtrConstObj {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs
index 7b643901..853d77af 100644
--- a/tests/expectations/tests/derive-hash-template-def-float.rs
+++ b/tests/expectations/tests/derive-hash-template-def-float.rs
@@ -5,9 +5,9 @@
-/// Template definition containing a float, which cannot derive hash/eq but can derive partialeq.
+/// Template definition containing a float, which cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd.
#[repr(C)]
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
pub struct foo<T> {
pub data: T,
pub b: f32,
diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs
index 7bca45b3..4fd935aa 100644
--- a/tests/expectations/tests/derive-hash-template-inst-float.rs
+++ b/tests/expectations/tests/derive-hash-template-inst-float.rs
@@ -5,9 +5,9 @@
-/// Template definition that doesn't contain float can derive hash/partialeq/eq
+/// Template definition that doesn't contain float can derive Hash/PartialOrd/Ord/PartialEq/Eq
#[repr(C)]
-#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct foo<T> {
pub data: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
@@ -17,9 +17,9 @@ impl<T> Default for foo<T> {
unsafe { ::std::mem::zeroed() }
}
}
-/// Can derive hash/partialeq/eq when instantiated with int
+/// Can derive Hash/PartialOrd/Ord/PartialEq/Eq when instantiated with int
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct IntStr {
pub a: foo<::std::os::raw::c_int>,
}
@@ -46,19 +46,14 @@ fn bindgen_test_layout_IntStr() {
)
);
}
-impl Clone for IntStr {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for IntStr {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
-/// Cannot derive hash/eq when instantiated with float but can derive partialeq
+/// Cannot derive Hash/Eq/Ord when instantiated with float but can derive PartialEq/PartialOrd
#[repr(C)]
-#[derive(Debug, Copy, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
pub struct FloatStr {
pub a: foo<f32>,
}
@@ -85,11 +80,6 @@ fn bindgen_test_layout_FloatStr() {
)
);
}
-impl Clone for FloatStr {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for FloatStr {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -102,13 +92,31 @@ fn __bindgen_test_layout_foo_open0_int_close0_instantiation() {
4usize,
concat!(
"Size of template specialization: ",
- stringify ! ( foo < :: std :: os :: raw :: c_int > )
+ stringify!(foo<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(foo<::std::os::raw::c_int>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < foo < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( foo < :: std :: os :: raw :: c_int > ) ) );
}
#[test]
fn __bindgen_test_layout_foo_open0_float_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < foo < f32 > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( foo < f32 > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < foo < f32 > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( foo < f32 > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<foo<f32>>(),
+ 4usize,
+ concat!("Size of template specialization: ", stringify!(foo<f32>))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo<f32>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(foo<f32>)
+ )
+ );
}
diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs
new file mode 100644
index 00000000..73972d70
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-anonfield.rs
@@ -0,0 +1,47 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct rte_mbuf {
+ pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1,
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union rte_mbuf__bindgen_ty_1 {
+ _bindgen_union_align: [u8; 0usize],
+}
+#[test]
+fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() {
+ assert_eq!(
+ ::std::mem::size_of::<rte_mbuf__bindgen_ty_1>(),
+ 0usize,
+ concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_mbuf__bindgen_ty_1>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1))
+ );
+}
+impl Default for rte_mbuf__bindgen_ty_1 {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[test]
+fn bindgen_test_layout_rte_mbuf() {
+ assert_eq!(
+ ::std::mem::size_of::<rte_mbuf>(),
+ 0usize,
+ concat!("Size of: ", stringify!(rte_mbuf))
+ );
+}
+impl Default for rte_mbuf {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs
new file mode 100644
index 00000000..cb86ebe6
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-base.rs
@@ -0,0 +1,72 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct Base {
+ pub large: [::std::os::raw::c_int; 33usize],
+}
+#[test]
+fn bindgen_test_layout_Base() {
+ assert_eq!(
+ ::std::mem::size_of::<Base>(),
+ 132usize,
+ concat!("Size of: ", stringify!(Base))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Base>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Base))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Base)).large as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Base),
+ "::",
+ stringify!(large)
+ )
+ );
+}
+impl Default for Base {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for Base {
+ fn eq(&self, other: &Base) -> bool {
+ &self.large[..] == &other.large[..]
+ }
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct ShouldDerivePartialEq {
+ pub _base: Base,
+}
+#[test]
+fn bindgen_test_layout_ShouldDerivePartialEq() {
+ assert_eq!(
+ ::std::mem::size_of::<ShouldDerivePartialEq>(),
+ 132usize,
+ concat!("Size of: ", stringify!(ShouldDerivePartialEq))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ShouldDerivePartialEq>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ShouldDerivePartialEq))
+ );
+}
+impl Default for ShouldDerivePartialEq {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for ShouldDerivePartialEq {
+ fn eq(&self, other: &ShouldDerivePartialEq) -> bool {
+ self._base == other._base
+ }
+}
diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs
new file mode 100644
index 00000000..b9e2db29
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-bitfield.rs
@@ -0,0 +1,125 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct C {
+ pub _bitfield_1: u8,
+ pub large_array: [::std::os::raw::c_int; 50usize],
+}
+#[test]
+fn bindgen_test_layout_C() {
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 204usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).large_array as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(large_array)
+ )
+ );
+}
+impl Default for C {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for C {
+ fn eq(&self, other: &C) -> bool {
+ self.a() == other.a() && self.b() == other.b()
+ && &self.large_array[..] == &other.large_array[..]
+ }
+}
+impl C {
+ #[inline]
+ pub fn a(&self) -> bool {
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ let mask = 0x1 as u8;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u8) }
+ }
+ #[inline]
+ pub fn set_a(&mut self, val: bool) {
+ let mask = 0x1 as u8;
+ let val = val as u8 as u8;
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn b(&self) -> bool {
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ let mask = 0xfe as u8;
+ let val = (unit_field_val & mask) >> 1usize;
+ unsafe { ::std::mem::transmute(val as u8) }
+ }
+ #[inline]
+ pub fn set_b(&mut self, val: bool) {
+ let mask = 0xfe as u8;
+ let val = val as u8 as u8;
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 1usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(a: bool, b: bool) -> u8 {
+ ((0 | ((a as u8 as u8) << 0usize) & (0x1 as u8))
+ | ((b as u8 as u8) << 1usize) & (0xfe as u8))
+ }
+}
diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs
new file mode 100644
index 00000000..7b925fba
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-core.rs
@@ -0,0 +1,45 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+extern crate core;
+
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct C {
+ pub large_array: [::std::os::raw::c_int; 420usize],
+}
+#[test]
+fn bindgen_test_layout_C() {
+ assert_eq!(
+ ::core::mem::size_of::<C>(),
+ 1680usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::core::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).large_array as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(large_array)
+ )
+ );
+}
+impl Default for C {
+ fn default() -> Self {
+ unsafe { ::core::mem::zeroed() }
+ }
+}
+impl ::core::cmp::PartialEq for C {
+ fn eq(&self, other: &C) -> bool {
+ &self.large_array[..] == &other.large_array[..]
+ }
+}
diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs
new file mode 100644
index 00000000..52a4bf71
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-pointer.rs
@@ -0,0 +1,109 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct Bar {
+ pub b: *mut a,
+}
+#[test]
+fn bindgen_test_layout_Bar() {
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).b as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(b))
+ );
+}
+impl Default for Bar {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct c {
+ pub __bindgen_anon_1: c__bindgen_ty_1,
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union c__bindgen_ty_1 {
+ _bindgen_union_align: u8,
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_c__bindgen_ty_1() {
+ assert_eq!(
+ ::std::mem::size_of::<c__bindgen_ty_1>(),
+ 1usize,
+ concat!("Size of: ", stringify!(c__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<c__bindgen_ty_1>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(c__bindgen_ty_1))
+ );
+}
+impl Default for c__bindgen_ty_1 {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[test]
+fn bindgen_test_layout_c() {
+ assert_eq!(
+ ::std::mem::size_of::<c>(),
+ 1usize,
+ concat!("Size of: ", stringify!(c))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<c>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(c))
+ );
+}
+impl Default for c {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct a {
+ pub d: c,
+}
+#[test]
+fn bindgen_test_layout_a() {
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 1usize,
+ concat!("Size of: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const a)).d as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(a), "::", stringify!(d))
+ );
+}
+impl Default for a {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs
new file mode 100644
index 00000000..c2642062
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-union.rs
@@ -0,0 +1,53 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+
+/// Deriving PartialEq for rust unions is not supported.
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union ShouldNotDerivePartialEq {
+ pub a: ::std::os::raw::c_char,
+ pub b: ::std::os::raw::c_int,
+ _bindgen_union_align: u32,
+}
+#[test]
+fn bindgen_test_layout_ShouldNotDerivePartialEq() {
+ assert_eq!(
+ ::std::mem::size_of::<ShouldNotDerivePartialEq>(),
+ 4usize,
+ concat!("Size of: ", stringify!(ShouldNotDerivePartialEq))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ShouldNotDerivePartialEq>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ShouldNotDerivePartialEq)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ShouldNotDerivePartialEq),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ShouldNotDerivePartialEq)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ShouldNotDerivePartialEq),
+ "::",
+ stringify!(b)
+ )
+ );
+}
+impl Default for ShouldNotDerivePartialEq {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs
new file mode 100644
index 00000000..32a06352
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs
@@ -0,0 +1,105 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
+impl<T> __BindgenUnionField<T> {
+ #[inline]
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
+ #[inline]
+ pub unsafe fn as_ref(&self) -> &T {
+ ::std::mem::transmute(self)
+ }
+ #[inline]
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
+}
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
+ #[inline]
+ fn default() -> Self {
+ Self::new()
+ }
+}
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
+ #[inline]
+ fn clone(&self) -> Self {
+ Self::new()
+ }
+}
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
+}
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
+}
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
+/// 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() {
+ assert_eq!(
+ ::std::mem::size_of::<ShouldDerivePartialEq>(),
+ 152usize,
+ concat!("Size of: ", stringify!(ShouldDerivePartialEq))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ShouldDerivePartialEq>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ShouldDerivePartialEq))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ShouldDerivePartialEq)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ShouldDerivePartialEq),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ShouldDerivePartialEq)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ShouldDerivePartialEq),
+ "::",
+ stringify!(b)
+ )
+ );
+}
+impl Clone for ShouldDerivePartialEq {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+impl Default for ShouldDerivePartialEq {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for ShouldDerivePartialEq {
+ fn eq(&self, other: &ShouldDerivePartialEq) -> bool {
+ &self.bindgen_union_field[..] == &other.bindgen_union_field[..]
+ }
+}
diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs
index 114b73e3..98307774 100644
--- a/tests/expectations/tests/do-not-derive-copy.rs
+++ b/tests/expectations/tests/do-not-derive-copy.rs
@@ -11,18 +11,27 @@ pub struct WouldBeCopyButWeAreNotDerivingCopy {
}
#[test]
fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() {
- assert_eq!(::std::mem::size_of::<WouldBeCopyButWeAreNotDerivingCopy>() ,
- 4usize , concat ! (
- "Size of: " , stringify ! ( WouldBeCopyButWeAreNotDerivingCopy
- ) ));
- assert_eq! (::std::mem::align_of::<WouldBeCopyButWeAreNotDerivingCopy>() ,
- 4usize , concat ! (
- "Alignment of " , stringify ! (
- WouldBeCopyButWeAreNotDerivingCopy ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WouldBeCopyButWeAreNotDerivingCopy ) ) .
- x as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- WouldBeCopyButWeAreNotDerivingCopy ) , "::" , stringify ! ( x
- ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WouldBeCopyButWeAreNotDerivingCopy>(),
+ 4usize,
+ concat!("Size of: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WouldBeCopyButWeAreNotDerivingCopy>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(WouldBeCopyButWeAreNotDerivingCopy)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WouldBeCopyButWeAreNotDerivingCopy)).x as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WouldBeCopyButWeAreNotDerivingCopy),
+ "::",
+ stringify!(x)
+ )
+ );
}
diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs
index 292533d9..2da07ded 100644
--- a/tests/expectations/tests/doggo-or-null.rs
+++ b/tests/expectations/tests/doggo-or-null.rs
@@ -5,39 +5,50 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq)]
pub struct Doggo {
pub x: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Doggo() {
- assert_eq!(::std::mem::size_of::<Doggo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Doggo ) ));
- assert_eq! (::std::mem::align_of::<Doggo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Doggo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Doggo ) ) . x as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Doggo ) , "::" ,
- stringify ! ( x ) ));
-}
-impl Clone for Doggo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Doggo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Doggo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Doggo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Doggo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Doggo)).x as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Doggo),
+ "::",
+ stringify!(x)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq)]
+#[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::<Null>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Null ) ));
- assert_eq! (::std::mem::align_of::<Null>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Null ) ));
-}
-impl Clone for Null {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Null>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Null))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Null>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Null))
+ );
}
/// This type is an opaque union. Unions can't derive anything interesting like
/// Debug or Default, even if their layout can, because it would require knowing
@@ -46,20 +57,25 @@ impl Clone for Null {
/// probably emit an opaque struct for opaque unions... but until then, we have
/// this test to make sure that opaque unions don't derive and still compile.
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union DoggoOrNull {
pub _bindgen_opaque_blob: u32,
}
#[test]
fn bindgen_test_layout_DoggoOrNull() {
- assert_eq!(::std::mem::size_of::<DoggoOrNull>() , 4usize , concat ! (
- "Size of: " , stringify ! ( DoggoOrNull ) ));
- assert_eq! (::std::mem::align_of::<DoggoOrNull>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( DoggoOrNull ) ));
-}
-impl Clone for DoggoOrNull {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<DoggoOrNull>(),
+ 4usize,
+ concat!("Size of: ", stringify!(DoggoOrNull))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DoggoOrNull>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(DoggoOrNull))
+ );
}
impl Default for DoggoOrNull {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs
index 67ca77d6..9732849c 100644
--- a/tests/expectations/tests/duplicated-namespaces-definitions.rs
+++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs
@@ -12,57 +12,80 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub foo: ::std::os::raw::c_int,
pub baz: bool,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . foo as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . baz as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( baz ) ));
- }
- impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).foo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(foo)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).baz as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(baz)
+ )
+ );
}
}
pub mod bar {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Copy)]
+ #[derive(Debug, Copy, Clone)]
pub struct Foo {
pub ptr: *mut root::foo::Bar,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . ptr as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( ptr ) ));
- }
- impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).ptr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(ptr)
+ )
+ );
}
impl Default for Foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
}
}
diff --git a/tests/expectations/tests/elaborated.rs b/tests/expectations/tests/elaborated.rs
index fbbef1cf..f68b55af 100644
--- a/tests/expectations/tests/elaborated.rs
+++ b/tests/expectations/tests/elaborated.rs
@@ -6,6 +6,6 @@
pub type whatever_whatever_t = ::std::os::raw::c_int;
extern "C" {
- #[link_name = "_Z9somethingPKi"]
+ #[link_name = "\u{1}_Z9somethingPKi"]
pub fn something(wat: *const whatever_whatever_t);
}
diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs
index 9eafbbd2..70c30830 100644
--- a/tests/expectations/tests/enum.rs
+++ b/tests/expectations/tests/enum.rs
@@ -6,7 +6,13 @@
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo { Bar = 0, Qux = 1, }
+pub enum Foo {
+ Bar = 0,
+ Qux = 1,
+}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Neg { MinusOne = -1, One = 1, }
+pub enum Neg {
+ MinusOne = -1,
+ One = 1,
+}
diff --git a/tests/expectations/tests/enum_alias.rs b/tests/expectations/tests/enum_alias.rs
index c77bf11d..f12c08d3 100644
--- a/tests/expectations/tests/enum_alias.rs
+++ b/tests/expectations/tests/enum_alias.rs
@@ -6,4 +6,6 @@
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Bar { VAL = 0, }
+pub enum Bar {
+ VAL = 0,
+}
diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs
index 9cdd1127..ffdcedd5 100644
--- a/tests/expectations/tests/enum_and_vtable_mangling.rs
+++ b/tests/expectations/tests/enum_and_vtable_mangling.rs
@@ -8,33 +8,42 @@ pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_;
pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, }
+pub enum _bindgen_ty_1 {
+ match_ = 0,
+ whatever_else = 1,
+}
#[repr(C)]
pub struct C__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct C {
pub vtable_: *const C__bindgen_vtable,
pub i: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 16usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . i as * const _ as usize
- } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( i ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 16usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).i as *const _ as usize },
+ 8usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(i))
+ );
}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_ZN1C5matchEv"]
+ #[link_name = "\u{1}_ZN1C5matchEv"]
pub fn C_match(this: *mut ::std::os::raw::c_void);
}
diff --git a/tests/expectations/tests/enum_dupe.rs b/tests/expectations/tests/enum_dupe.rs
index 5b6102c9..a91999ed 100644
--- a/tests/expectations/tests/enum_dupe.rs
+++ b/tests/expectations/tests/enum_dupe.rs
@@ -7,4 +7,6 @@
pub const Foo_Dupe: Foo = Foo::Bar;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo { Bar = 1, }
+pub enum Foo {
+ Bar = 1,
+}
diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs
index 73fc23f5..7ff0ef51 100644
--- a/tests/expectations/tests/enum_explicit_type.rs
+++ b/tests/expectations/tests/enum_explicit_type.rs
@@ -6,19 +6,34 @@
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo { Bar = 0, Qux = 1, }
+pub enum Foo {
+ Bar = 0,
+ Qux = 1,
+}
#[repr(i8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Neg { MinusOne = -1, One = 1, }
+pub enum Neg {
+ MinusOne = -1,
+ One = 1,
+}
#[repr(u16)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Bigger { Much = 255, Larger = 256, }
+pub enum Bigger {
+ Much = 255,
+ Larger = 256,
+}
#[repr(i64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum MuchLong { MuchLow = -4294967296, }
+pub enum MuchLong {
+ MuchLow = -4294967296,
+}
#[repr(i64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum MuchLongLong { I64_MIN = -9223372036854775808, }
+pub enum MuchLongLong {
+ I64_MIN = -9223372036854775808,
+}
#[repr(u64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum MuchULongLong { MuchHigh = 4294967296, }
+pub enum MuchULongLong {
+ MuchHigh = 4294967296,
+}
diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs
index 8c819535..06dea126 100644
--- a/tests/expectations/tests/enum_in_template_with_typedef.rs
+++ b/tests/expectations/tests/enum_in_template_with_typedef.rs
@@ -14,4 +14,6 @@ pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category =
std_fbstring_core_Category::Foo;
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum std_fbstring_core_Category { Foo = 0, }
+pub enum std_fbstring_core_Category {
+ Foo = 0,
+}
diff --git a/tests/expectations/tests/enum_negative.rs b/tests/expectations/tests/enum_negative.rs
index b47fdf09..100f27db 100644
--- a/tests/expectations/tests/enum_negative.rs
+++ b/tests/expectations/tests/enum_negative.rs
@@ -6,4 +6,7 @@
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo { Bar = -2, Qux = 1, }
+pub enum Foo {
+ Bar = -2,
+ Qux = 1,
+}
diff --git a/tests/expectations/tests/enum_packed.rs b/tests/expectations/tests/enum_packed.rs
index 75b68ee1..cc85b553 100644
--- a/tests/expectations/tests/enum_packed.rs
+++ b/tests/expectations/tests/enum_packed.rs
@@ -6,10 +6,19 @@
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Foo { Bar = 0, Qux = 1, }
+pub enum Foo {
+ Bar = 0,
+ Qux = 1,
+}
#[repr(i8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Neg { MinusOne = -1, One = 1, }
+pub enum Neg {
+ MinusOne = -1,
+ One = 1,
+}
#[repr(u16)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Bigger { Much = 255, Larger = 256, }
+pub enum Bigger {
+ Much = 255,
+ Larger = 256,
+}
diff --git a/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs
new file mode 100644
index 00000000..9613a7f2
--- /dev/null
+++ b/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs
@@ -0,0 +1,7 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const a: u32 = 18446744073709551611;
diff --git a/tests/expectations/tests/extern.rs b/tests/expectations/tests/extern.rs
index 789ed438..e257b7bc 100644
--- a/tests/expectations/tests/extern.rs
+++ b/tests/expectations/tests/extern.rs
@@ -4,6 +4,7 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-pub type foo =
- ::std::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)
- -> ::std::os::raw::c_int>;
+pub type foo = ::std::option::Option<
+ unsafe extern "C" fn(bar: ::std::os::raw::c_int)
+ -> ::std::os::raw::c_int,
+>;
diff --git a/tests/expectations/tests/float128.rs b/tests/expectations/tests/float128.rs
index 2ca90d40..5dcc6c40 100644
--- a/tests/expectations/tests/float128.rs
+++ b/tests/expectations/tests/float128.rs
@@ -2,6 +2,3 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
-
diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs
index 6b078418..8ad45f10 100644
--- a/tests/expectations/tests/forward-declaration-autoptr.rs
+++ b/tests/expectations/tests/forward-declaration-autoptr.rs
@@ -21,7 +21,7 @@ impl<T> Default for RefPtr<T> {
}
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Bar {
pub m_member: RefPtr<Foo>,
}
@@ -48,11 +48,6 @@ fn bindgen_test_layout_Bar() {
)
);
}
-impl Clone for Bar {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for Bar {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -63,10 +58,14 @@ fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() {
assert_eq!(
::std::mem::size_of::<RefPtr<Foo>>(),
8usize,
+ concat!("Size of template specialization: ", stringify!(RefPtr<Foo>))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<RefPtr<Foo>>(),
+ 8usize,
concat!(
- "Size of template specialization: ",
- stringify ! ( RefPtr < Foo > )
+ "Alignment of template specialization: ",
+ stringify!(RefPtr<Foo>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < RefPtr < Foo > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( RefPtr < Foo > ) ) );
}
diff --git a/tests/expectations/tests/forward-enum-decl.rs b/tests/expectations/tests/forward-enum-decl.rs
index 8b705f2a..5502c4c4 100644
--- a/tests/expectations/tests/forward-enum-decl.rs
+++ b/tests/expectations/tests/forward-enum-decl.rs
@@ -6,4 +6,7 @@
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum CSSPseudoClassType { empty = 0, link = 1, }
+pub enum CSSPseudoClassType {
+ empty = 0,
+ link = 1,
+}
diff --git a/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/tests/expectations/tests/forward-inherit-struct-with-fields.rs
index 05c6d3ee..19772dbe 100644
--- a/tests/expectations/tests/forward-inherit-struct-with-fields.rs
+++ b/tests/expectations/tests/forward-inherit-struct-with-fields.rs
@@ -11,8 +11,10 @@ pub struct js_RootedBase<T> {
pub next: *mut Rooted<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for js_RootedBase<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for js_RootedBase<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -20,6 +22,8 @@ pub struct Rooted<T> {
pub _base: js_RootedBase<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Rooted<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Rooted<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/tests/expectations/tests/forward-inherit-struct.rs
index e3f2b225..a2399bcb 100644
--- a/tests/expectations/tests/forward-inherit-struct.rs
+++ b/tests/expectations/tests/forward-inherit-struct.rs
@@ -15,5 +15,7 @@ pub struct Rooted {
pub _address: u8,
}
impl Default for Rooted {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs
index 9baa2d8d..ceab52d7 100644
--- a/tests/expectations/tests/forward_declared_complex_types.rs
+++ b/tests/expectations/tests/forward_declared_complex_types.rs
@@ -5,19 +5,22 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo_empty {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo_empty() {
- assert_eq!(::std::mem::size_of::<Foo_empty>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo_empty ) ));
- assert_eq! (::std::mem::align_of::<Foo_empty>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo_empty ) ));
-}
-impl Clone for Foo_empty {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo_empty>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo_empty))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo_empty>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo_empty))
+ );
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -25,30 +28,35 @@ pub struct Foo {
_unused: [u8; 0],
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Bar {
pub f: *mut Foo,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . f as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( f ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).f as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(f))
+ );
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_Z10baz_structP3Foo"]
+ #[link_name = "\u{1}_Z10baz_structP3Foo"]
pub fn baz_struct(f: *mut Foo);
}
#[repr(C)]
@@ -57,7 +65,7 @@ pub struct Union {
_unused: [u8; 0],
}
extern "C" {
- #[link_name = "_Z9baz_unionP5Union"]
+ #[link_name = "\u{1}_Z9baz_unionP5Union"]
pub fn baz_union(u: *mut Union);
}
#[repr(C)]
@@ -66,6 +74,6 @@ pub struct Quux {
_unused: [u8; 0],
}
extern "C" {
- #[link_name = "_Z9baz_classP4Quux"]
+ #[link_name = "\u{1}_Z9baz_classP4Quux"]
pub fn baz_class(q: *mut Quux);
}
diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs
index 9baa2d8d..a4eaa17c 100644
--- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs
+++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs
@@ -11,13 +11,21 @@ pub struct Foo_empty {
}
#[test]
fn bindgen_test_layout_Foo_empty() {
- assert_eq!(::std::mem::size_of::<Foo_empty>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo_empty ) ));
- assert_eq! (::std::mem::align_of::<Foo_empty>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo_empty ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Foo_empty>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo_empty))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo_empty>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo_empty))
+ );
}
impl Clone for Foo_empty {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -31,24 +39,34 @@ pub struct Bar {
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . f as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( f ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).f as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(f))
+ );
}
impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_Z10baz_structP3Foo"]
+ #[link_name = "\u{1}_Z10baz_structP3Foo"]
pub fn baz_struct(f: *mut Foo);
}
#[repr(C)]
@@ -57,7 +75,7 @@ pub struct Union {
_unused: [u8; 0],
}
extern "C" {
- #[link_name = "_Z9baz_unionP5Union"]
+ #[link_name = "\u{1}_Z9baz_unionP5Union"]
pub fn baz_union(u: *mut Union);
}
#[repr(C)]
@@ -66,6 +84,6 @@ pub struct Quux {
_unused: [u8; 0],
}
extern "C" {
- #[link_name = "_Z9baz_classP4Quux"]
+ #[link_name = "\u{1}_Z9baz_classP4Quux"]
pub fn baz_class(q: *mut Quux);
}
diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs
index a0f0c137..001d6df0 100644
--- a/tests/expectations/tests/forward_declared_struct.rs
+++ b/tests/expectations/tests/forward_declared_struct.rs
@@ -5,40 +5,48 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct a {
pub b: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_a() {
- assert_eq!(::std::mem::size_of::<a>() , 4usize , concat ! (
- "Size of: " , stringify ! ( a ) ));
- assert_eq! (::std::mem::align_of::<a>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( a ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . b as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( a ) , "::" , stringify
- ! ( b ) ));
-}
-impl Clone for a {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 4usize,
+ concat!("Size of: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const a)).b as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(a), "::", stringify!(b))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct c {
pub d: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_c() {
- assert_eq!(::std::mem::size_of::<c>() , 4usize , concat ! (
- "Size of: " , stringify ! ( c ) ));
- assert_eq! (::std::mem::align_of::<c>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( c ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const c ) ) . d as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( c ) , "::" , stringify
- ! ( d ) ));
-}
-impl Clone for c {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<c>(),
+ 4usize,
+ concat!("Size of: ", stringify!(c))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<c>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(c))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const c)).d as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(c), "::", stringify!(d))
+ );
}
diff --git a/tests/expectations/tests/func_proto.rs b/tests/expectations/tests/func_proto.rs
index 789ed438..e257b7bc 100644
--- a/tests/expectations/tests/func_proto.rs
+++ b/tests/expectations/tests/func_proto.rs
@@ -4,6 +4,7 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-pub type foo =
- ::std::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)
- -> ::std::os::raw::c_int>;
+pub type foo = ::std::option::Option<
+ unsafe extern "C" fn(bar: ::std::os::raw::c_int)
+ -> ::std::os::raw::c_int,
+>;
diff --git a/tests/expectations/tests/func_ptr.rs b/tests/expectations/tests/func_ptr.rs
index fb3860a4..730849c0 100644
--- a/tests/expectations/tests/func_ptr.rs
+++ b/tests/expectations/tests/func_ptr.rs
@@ -5,11 +5,10 @@
extern "C" {
- #[link_name = "foo"]
+ #[link_name = "\u{1}foo"]
pub static mut foo:
- ::std::option::Option<unsafe extern "C" fn(x:
- ::std::os::raw::c_int,
- y:
- ::std::os::raw::c_int)
- -> ::std::os::raw::c_int>;
+ ::std::option::Option<
+ unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int)
+ -> ::std::os::raw::c_int,
+ >;
}
diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs
index e3d1abff..5a2c00c7 100644
--- a/tests/expectations/tests/func_ptr_in_struct.rs
+++ b/tests/expectations/tests/func_ptr_in_struct.rs
@@ -5,31 +5,39 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum baz { }
+pub enum baz {}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Foo {
- pub bar: ::std::option::Option<unsafe extern "C" fn(x:
- ::std::os::raw::c_int,
- y:
- ::std::os::raw::c_int)
- -> baz>,
+ pub bar: ::std::option::Option<
+ unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> baz,
+ >,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for Foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/gen-constructors-neg.rs b/tests/expectations/tests/gen-constructors-neg.rs
index c894b95c..36cae722 100644
--- a/tests/expectations/tests/gen-constructors-neg.rs
+++ b/tests/expectations/tests/gen-constructors-neg.rs
@@ -5,17 +5,20 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/gen-constructors.rs b/tests/expectations/tests/gen-constructors.rs
index c811efb8..cb2024a1 100644
--- a/tests/expectations/tests/gen-constructors.rs
+++ b/tests/expectations/tests/gen-constructors.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
@@ -23,14 +23,9 @@ fn bindgen_test_layout_Foo() {
);
}
extern "C" {
- #[link_name = "_ZN3FooC1Ei"]
+ #[link_name = "\u{1}_ZN3FooC1Ei"]
pub fn Foo_Foo(this: *mut Foo, a: ::std::os::raw::c_int);
}
-impl Clone for Foo {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Foo {
#[inline]
pub unsafe fn new(a: ::std::os::raw::c_int) -> Self {
diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs
index 64373d75..0f75ce0b 100644
--- a/tests/expectations/tests/gen-destructors-neg.rs
+++ b/tests/expectations/tests/gen-destructors-neg.rs
@@ -11,13 +11,24 @@ pub struct Foo {
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs
index 711d6f23..a7bf4028 100644
--- a/tests/expectations/tests/gen-destructors.rs
+++ b/tests/expectations/tests/gen-destructors.rs
@@ -11,21 +11,34 @@ pub struct Foo {
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZN3FooD1Ev"]
+ #[link_name = "\u{1}_ZN3FooD1Ev"]
pub fn Foo_Foo_destructor(this: *mut Foo);
}
impl Foo {
#[inline]
- pub unsafe fn destruct(&mut self) { Foo_Foo_destructor(self) }
+ pub unsafe fn destruct(&mut self) {
+ Foo_Foo_destructor(self)
+ }
}
diff --git a/tests/expectations/tests/generate-inline.rs b/tests/expectations/tests/generate-inline.rs
index 15f944d3..48d8f4f8 100644
--- a/tests/expectations/tests/generate-inline.rs
+++ b/tests/expectations/tests/generate-inline.rs
@@ -5,29 +5,34 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
extern "C" {
- #[link_name = "_ZN3Foo3barEv"]
+ #[link_name = "\u{1}_ZN3Foo3barEv"]
pub fn Foo_bar() -> ::std::os::raw::c_int;
}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
-}
impl Foo {
#[inline]
- pub unsafe fn bar() -> ::std::os::raw::c_int { Foo_bar() }
+ pub unsafe fn bar() -> ::std::os::raw::c_int {
+ Foo_bar()
+ }
}
extern "C" {
- #[link_name = "_Z3foov"]
+ #[link_name = "\u{1}_Z3foov"]
pub fn foo() -> ::std::os::raw::c_int;
}
diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs
new file mode 100644
index 00000000..cf8b283c
--- /dev/null
+++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs
@@ -0,0 +1,208 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+pub struct BaseWithVtable__bindgen_vtable(::std::os::raw::c_void);
+/// This should have an explicit vtable.
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct BaseWithVtable<T> {
+ pub vtable_: *const BaseWithVtable__bindgen_vtable,
+ pub t: T,
+ pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
+}
+impl<T> Default for BaseWithVtable<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+/// This should not have an explicit vtable.
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct DerivedWithNoVirtualMethods {
+ pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_DerivedWithNoVirtualMethods() {
+ assert_eq!(
+ ::std::mem::size_of::<DerivedWithNoVirtualMethods>(),
+ 16usize,
+ concat!("Size of: ", stringify!(DerivedWithNoVirtualMethods))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DerivedWithNoVirtualMethods>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(DerivedWithNoVirtualMethods))
+ );
+}
+impl Default for DerivedWithNoVirtualMethods {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+/// This should not have an explicit vtable.
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct DerivedWithVirtualMethods {
+ pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_DerivedWithVirtualMethods() {
+ assert_eq!(
+ ::std::mem::size_of::<DerivedWithVirtualMethods>(),
+ 16usize,
+ concat!("Size of: ", stringify!(DerivedWithVirtualMethods))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DerivedWithVirtualMethods>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(DerivedWithVirtualMethods))
+ );
+}
+impl Default for DerivedWithVirtualMethods {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+/// This should not have any vtable.
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct BaseWithoutVtable<U> {
+ pub u: U,
+ pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
+}
+impl<U> Default for BaseWithoutVtable<U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[repr(C)]
+pub struct DerivedWithVtable__bindgen_vtable(::std::os::raw::c_void);
+/// This should have an explicit vtable.
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+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::<DerivedWithVtable>(),
+ 16usize,
+ concat!("Size of: ", stringify!(DerivedWithVtable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DerivedWithVtable>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(DerivedWithVtable))
+ );
+}
+impl Default for DerivedWithVtable {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+/// This should not have any vtable.
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct DerivedWithoutVtable {
+ pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_DerivedWithoutVtable() {
+ assert_eq!(
+ ::std::mem::size_of::<DerivedWithoutVtable>(),
+ 8usize,
+ concat!("Size of: ", stringify!(DerivedWithoutVtable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DerivedWithoutVtable>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(DerivedWithoutVtable))
+ );
+}
+impl Default for DerivedWithoutVtable {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+#[test]
+fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation() {
+ assert_eq!(
+ ::std::mem::size_of::<BaseWithVtable<*mut ::std::os::raw::c_char>>(),
+ 16usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BaseWithVtable<*mut ::std::os::raw::c_char>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+}
+#[test]
+fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation_1() {
+ assert_eq!(
+ ::std::mem::size_of::<BaseWithVtable<*mut ::std::os::raw::c_char>>(),
+ 16usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BaseWithVtable<*mut ::std::os::raw::c_char>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+}
+#[test]
+fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation() {
+ assert_eq!(
+ ::std::mem::size_of::<BaseWithoutVtable<*mut ::std::os::raw::c_char>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BaseWithoutVtable<*mut ::std::os::raw::c_char>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+}
+#[test]
+fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation_1() {
+ assert_eq!(
+ ::std::mem::size_of::<BaseWithoutVtable<*mut ::std::os::raw::c_char>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BaseWithoutVtable<*mut ::std::os::raw::c_char>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>)
+ )
+ );
+}
diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs
index e3f2b225..a2399bcb 100644
--- a/tests/expectations/tests/inherit-namespaced.rs
+++ b/tests/expectations/tests/inherit-namespaced.rs
@@ -15,5 +15,7 @@ pub struct Rooted {
pub _address: u8,
}
impl Default for Rooted {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs
index 0503804a..fadf270e 100644
--- a/tests/expectations/tests/inherit_named.rs
+++ b/tests/expectations/tests/inherit_named.rs
@@ -15,6 +15,8 @@ pub struct Weeee<T> {
pub _base: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Weeee<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Weeee<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs
index 85af3e03..49e842d7 100644
--- a/tests/expectations/tests/inherit_typedef.rs
+++ b/tests/expectations/tests/inherit_typedef.rs
@@ -5,33 +5,39 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
pub type TypedefedFoo = Foo;
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
}
diff --git a/tests/expectations/tests/inline-function.rs b/tests/expectations/tests/inline-function.rs
index 2ca90d40..5dcc6c40 100644
--- a/tests/expectations/tests/inline-function.rs
+++ b/tests/expectations/tests/inline-function.rs
@@ -2,6 +2,3 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
-
diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs
index 13f3b8ee..ade3ce3b 100644
--- a/tests/expectations/tests/inline_namespace.rs
+++ b/tests/expectations/tests/inline_namespace.rs
@@ -14,23 +14,31 @@ pub mod root {
pub type Ty = ::std::os::raw::c_int;
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub baz: root::foo::Ty,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( baz ) ));
- }
- impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(baz)
+ )
+ );
}
}
diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs
index 406d9f5e..7895a19f 100644
--- a/tests/expectations/tests/inline_namespace_conservative.rs
+++ b/tests/expectations/tests/inline_namespace_conservative.rs
@@ -19,23 +19,31 @@ pub mod root {
pub type Ty = ::std::os::raw::c_longlong;
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub baz: root::foo::bar::Ty,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( baz ) ));
- }
- impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(baz)
+ )
+ );
}
}
diff --git a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs
index c2592e57..e208f0dc 100644
--- a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs
+++ b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs
@@ -18,7 +18,9 @@ pub struct std_basic_string_Alloc_hider {
pub storage: *mut ::std::os::raw::c_void,
}
impl Default for std_basic_string_Alloc_hider {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug)]
@@ -26,9 +28,13 @@ pub struct std_basic_string__bindgen_ty_1<CharT> {
pub inline_storage: [CharT; 4usize],
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<CharT>>,
}
-impl <CharT> Default for std_basic_string__bindgen_ty_1<CharT> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<CharT> Default for std_basic_string__bindgen_ty_1<CharT> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-impl <CharT> Default for std_basic_string<CharT> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<CharT> Default for std_basic_string<CharT> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs
index dd92dac9..3ea87edb 100644
--- a/tests/expectations/tests/inner_const.rs
+++ b/tests/expectations/tests/inner_const.rs
@@ -5,30 +5,38 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub bar: ::std::os::raw::c_int,
}
extern "C" {
- #[link_name = "_ZN3Foo3BOOE"]
+ #[link_name = "\u{1}_ZN3Foo3BOOE"]
pub static mut Foo_BOO: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "_ZN3Foo8whateverE"]
+ #[link_name = "\u{1}_ZN3Foo8whateverE"]
pub static mut Foo_whatever: Foo;
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs
index b94ba60f..bf39e065 100644
--- a/tests/expectations/tests/inner_template_self.rs
+++ b/tests/expectations/tests/inner_template_self.rs
@@ -11,37 +11,56 @@ pub struct LinkedList {
pub prev: *mut LinkedList,
}
impl Default for LinkedList {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct InstantiateIt {
pub m_list: LinkedList,
}
#[test]
fn bindgen_test_layout_InstantiateIt() {
- assert_eq!(::std::mem::size_of::<InstantiateIt>() , 16usize , concat ! (
- "Size of: " , stringify ! ( InstantiateIt ) ));
- assert_eq! (::std::mem::align_of::<InstantiateIt>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( InstantiateIt ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const InstantiateIt ) ) . m_list as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( InstantiateIt ) , "::"
- , stringify ! ( m_list ) ));
-}
-impl Clone for InstantiateIt {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<InstantiateIt>(),
+ 16usize,
+ concat!("Size of: ", stringify!(InstantiateIt))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<InstantiateIt>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(InstantiateIt))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const InstantiateIt)).m_list as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(InstantiateIt),
+ "::",
+ stringify!(m_list)
+ )
+ );
}
impl Default for InstantiateIt {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<LinkedList>() , 16usize , concat ! (
- "Size of template specialization: " , stringify ! ( LinkedList
- ) ));
- assert_eq!(::std::mem::align_of::<LinkedList>() , 8usize , concat ! (
- "Alignment of template specialization: " , stringify ! (
- LinkedList ) ));
+ assert_eq!(
+ ::std::mem::size_of::<LinkedList>(),
+ 16usize,
+ concat!("Size of template specialization: ", stringify!(LinkedList))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<LinkedList>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(LinkedList)
+ )
+ );
}
diff --git a/tests/expectations/tests/int128_t.rs b/tests/expectations/tests/int128_t.rs
index 2ca90d40..5dcc6c40 100644
--- a/tests/expectations/tests/int128_t.rs
+++ b/tests/expectations/tests/int128_t.rs
@@ -2,6 +2,3 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
-
diff --git a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs
new file mode 100644
index 00000000..26510910
--- /dev/null
+++ b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs
@@ -0,0 +1,12 @@
+/* automatically generated by rust-bindgen */
+
+
+#![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 type a__bindgen_ty_1 = i32;
diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs
new file mode 100644
index 00000000..b0c4b529
--- /dev/null
+++ b/tests/expectations/tests/issue-1034.rs
@@ -0,0 +1,30 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C, packed)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct S2 {
+ pub _bitfield_1: u16,
+}
+#[test]
+fn bindgen_test_layout_S2() {
+ assert_eq!(
+ ::std::mem::size_of::<S2>(),
+ 2usize,
+ concat!("Size of: ", stringify!(S2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<S2>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(S2))
+ );
+}
+impl S2 {
+ #[inline]
+ pub fn new_bitfield_1() -> u16 {
+ 0
+ }
+}
diff --git a/tests/expectations/tests/issue-1040.rs b/tests/expectations/tests/issue-1040.rs
new file mode 100644
index 00000000..3271d0e8
--- /dev/null
+++ b/tests/expectations/tests/issue-1040.rs
@@ -0,0 +1,7 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const g_107: ::std::os::raw::c_ulonglong = 18446744073709551615;
diff --git a/tests/expectations/tests/issue-358.rs b/tests/expectations/tests/issue-358.rs
index c094b333..892148aa 100644
--- a/tests/expectations/tests/issue-358.rs
+++ b/tests/expectations/tests/issue-358.rs
@@ -10,7 +10,9 @@ pub struct JS_PersistentRooted {
pub _base: a,
}
impl Default for JS_PersistentRooted {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -18,5 +20,7 @@ pub struct a {
pub b: *mut a,
}
impl Default for a {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs
index 6924d0a9..84a33cb9 100644
--- a/tests/expectations/tests/issue-372.rs
+++ b/tests/expectations/tests/issue-372.rs
@@ -9,7 +9,7 @@ pub mod root {
#[allow(unused_imports)]
use self::super::root;
#[repr(C)]
- #[derive(Debug, Copy)]
+ #[derive(Debug, Copy, Clone)]
pub struct i {
pub j: *mut root::i,
pub k: *mut root::i,
@@ -17,54 +17,64 @@ pub mod root {
}
#[test]
fn bindgen_test_layout_i() {
- assert_eq!(::std::mem::size_of::<i>() , 24usize , concat ! (
- "Size of: " , stringify ! ( i ) ));
- assert_eq! (::std::mem::align_of::<i>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( i ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const i ) ) . j as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( i ) , "::" ,
- stringify ! ( j ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const i ) ) . k as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( i ) , "::" ,
- stringify ! ( k ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const i ) ) . l as * const _ as usize } ,
- 16usize , concat ! (
- "Alignment of field: " , stringify ! ( i ) , "::" ,
- stringify ! ( l ) ));
- }
- impl Clone for i {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<i>(),
+ 24usize,
+ concat!("Size of: ", stringify!(i))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<i>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(i))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const i)).j as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(i), "::", stringify!(j))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const i)).k as *const _ as usize },
+ 8usize,
+ concat!("Alignment of field: ", stringify!(i), "::", stringify!(k))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const i)).l as *const _ as usize },
+ 16usize,
+ concat!("Alignment of field: ", stringify!(i), "::", stringify!(l))
+ );
}
impl Default for i {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
- #[derive(Debug, Copy)]
+ #[derive(Debug, Copy, Clone)]
pub struct d {
pub m: root::i,
}
#[test]
fn bindgen_test_layout_d() {
- assert_eq!(::std::mem::size_of::<d>() , 24usize , concat ! (
- "Size of: " , stringify ! ( d ) ));
- assert_eq! (::std::mem::align_of::<d>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( d ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const d ) ) . m as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( d ) , "::" ,
- stringify ! ( m ) ));
- }
- impl Clone for d {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<d>(),
+ 24usize,
+ concat!("Size of: ", stringify!(d))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<d>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(d))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const d)).m as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(d), "::", stringify!(m))
+ );
}
impl Default for d {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -88,17 +98,25 @@ pub mod root {
}
#[test]
fn bindgen_test_layout_F() {
- assert_eq!(::std::mem::size_of::<F>() , 264usize , concat ! (
- "Size of: " , stringify ! ( F ) ));
- assert_eq! (::std::mem::align_of::<F>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( F ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const F ) ) . w as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( F ) , "::" ,
- stringify ! ( w ) ));
+ assert_eq!(
+ ::std::mem::size_of::<F>(),
+ 264usize,
+ concat!("Size of: ", stringify!(F))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<F>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(F))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const F)).w as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(F), "::", stringify!(w))
+ );
}
impl Default for F {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
}
diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs
index b0366f1c..928701ef 100644
--- a/tests/expectations/tests/issue-410.rs
+++ b/tests/expectations/tests/issue-410.rs
@@ -12,7 +12,7 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Value {
pub _address: u8,
}
@@ -30,14 +30,9 @@ pub mod root {
);
}
extern "C" {
- #[link_name = "_ZN2JS5Value1aE10JSWhyMagic"]
+ #[link_name = "\u{1}_ZN2JS5Value1aE10JSWhyMagic"]
pub fn Value_a(this: *mut root::JS::Value, arg1: root::JSWhyMagic);
}
- impl Clone for Value {
- fn clone(&self) -> Self {
- *self
- }
- }
impl Value {
#[inline]
pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) {
@@ -46,5 +41,5 @@ pub mod root {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
- pub enum JSWhyMagic { }
+ pub enum JSWhyMagic {}
}
diff --git a/tests/expectations/tests/issue-446.rs b/tests/expectations/tests/issue-446.rs
index d416548d..d5634d53 100644
--- a/tests/expectations/tests/issue-446.rs
+++ b/tests/expectations/tests/issue-446.rs
@@ -10,7 +10,9 @@ pub struct List {
pub next: *mut List,
}
impl Default for List {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -18,5 +20,7 @@ pub struct PersistentRooted {
pub root_list: List,
}
impl Default for PersistentRooted {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-447.rs b/tests/expectations/tests/issue-447.rs
index 7102235f..11a99ad1 100644
--- a/tests/expectations/tests/issue-447.rs
+++ b/tests/expectations/tests/issue-447.rs
@@ -15,7 +15,7 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct GuardObjectNotifier {
pub _address: u8,
}
@@ -32,15 +32,10 @@ pub mod root {
concat!("Alignment of ", stringify!(GuardObjectNotifier))
);
}
- impl Clone for GuardObjectNotifier {
- fn clone(&self) -> Self {
- *self
- }
- }
}
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct JSAutoCompartment {
pub _address: u8,
}
@@ -58,17 +53,12 @@ pub mod root {
);
}
extern "C" {
- #[link_name = "_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"]
+ #[link_name = "\u{1}_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"]
pub fn JSAutoCompartment_JSAutoCompartment(
this: *mut root::JSAutoCompartment,
arg1: root::mozilla::detail::GuardObjectNotifier,
);
}
- impl Clone for JSAutoCompartment {
- fn clone(&self) -> Self {
- *self
- }
- }
impl JSAutoCompartment {
#[inline]
pub unsafe fn new(arg1: root::mozilla::detail::GuardObjectNotifier) -> Self {
diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs
index 7a947366..8975938d 100644
--- a/tests/expectations/tests/issue-493.rs
+++ b/tests/expectations/tests/issue-493.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct basic_string {
@@ -51,13 +63,17 @@ pub struct basic_string___long {
pub __data_: basic_string_pointer,
}
impl Default for basic_string___long {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub const basic_string___min_cap: basic_string__bindgen_ty_1 =
basic_string__bindgen_ty_1::__min_cap;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum basic_string__bindgen_ty_1 { __min_cap = 0, }
+pub enum basic_string__bindgen_ty_1 {
+ __min_cap = 0,
+}
#[repr(C)]
pub struct basic_string___short {
pub __bindgen_anon_1: basic_string___short__bindgen_ty_1,
@@ -70,10 +86,14 @@ pub union basic_string___short__bindgen_ty_1 {
_bindgen_union_align: u8,
}
impl Default for basic_string___short__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl Default for basic_string___short {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct basic_string___ulx {
@@ -82,20 +102,26 @@ pub struct basic_string___ulx {
pub bindgen_union_field: [u8; 0usize],
}
impl Default for basic_string___ulx {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub const basic_string___n_words: basic_string__bindgen_ty_2 =
basic_string__bindgen_ty_2::__n_words;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum basic_string__bindgen_ty_2 { __n_words = 0, }
+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 { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct basic_string___rep {
@@ -109,8 +135,12 @@ pub struct basic_string___rep__bindgen_ty_1 {
pub bindgen_union_field: [u8; 0usize],
}
impl Default for basic_string___rep__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl Default for basic_string___rep {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs
index 710cd41e..da6dac77 100644
--- a/tests/expectations/tests/issue-493_1_0.rs
+++ b/tests/expectations/tests/issue-493_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct basic_string {
@@ -51,13 +63,17 @@ pub struct basic_string___long {
pub __data_: basic_string_pointer,
}
impl Default for basic_string___long {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub const basic_string___min_cap: basic_string__bindgen_ty_1 =
basic_string__bindgen_ty_1::__min_cap;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum basic_string__bindgen_ty_1 { __min_cap = 0, }
+pub enum basic_string__bindgen_ty_1 {
+ __min_cap = 0,
+}
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct basic_string___short {
@@ -72,7 +88,9 @@ pub struct basic_string___short__bindgen_ty_1 {
pub bindgen_union_field: u8,
}
impl Default for basic_string___short {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Copy, Clone)]
@@ -82,20 +100,26 @@ pub struct basic_string___ulx {
pub bindgen_union_field: [u8; 0usize],
}
impl Default for basic_string___ulx {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub const basic_string___n_words: basic_string__bindgen_ty_2 =
basic_string__bindgen_ty_2::__n_words;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum basic_string__bindgen_ty_2 { __n_words = 0, }
+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 { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Copy, Clone)]
@@ -111,8 +135,12 @@ pub struct basic_string___rep__bindgen_ty_1 {
pub bindgen_union_field: [u8; 0usize],
}
impl Default for basic_string___rep__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl Default for basic_string___rep {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/tests/expectations/tests/issue-544-stylo-creduce-2.rs
index e217fe24..071111a4 100644
--- a/tests/expectations/tests/issue-544-stylo-creduce-2.rs
+++ b/tests/expectations/tests/issue-544-stylo-creduce-2.rs
@@ -11,5 +11,7 @@ pub struct Foo {
pub type Foo_FirstAlias = [u8; 0usize];
pub type Foo_SecondAlias = [u8; 0usize];
impl Default for Foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs
index 3eae9488..b2ddf713 100644
--- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs
+++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs
@@ -8,7 +8,10 @@ pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1;
pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _bindgen_ty_1 { ENUM_VARIANT_1 = 0, ENUM_VARIANT_2 = 1, }
+pub enum _bindgen_ty_1 {
+ ENUM_VARIANT_1 = 0,
+ ENUM_VARIANT_2 = 1,
+}
pub type JS_Alias = u8;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -16,32 +19,46 @@ pub struct JS_Base {
pub f: JS_Alias,
}
impl Default for JS_Base {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct JS_AutoIdVector {
pub _base: JS_Base,
}
#[test]
fn bindgen_test_layout_JS_AutoIdVector() {
- assert_eq!(::std::mem::size_of::<JS_AutoIdVector>() , 1usize , concat ! (
- "Size of: " , stringify ! ( JS_AutoIdVector ) ));
- assert_eq! (::std::mem::align_of::<JS_AutoIdVector>() , 1usize , concat !
- ( "Alignment of " , stringify ! ( JS_AutoIdVector ) ));
-}
-impl Clone for JS_AutoIdVector {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<JS_AutoIdVector>(),
+ 1usize,
+ concat!("Size of: ", stringify!(JS_AutoIdVector))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<JS_AutoIdVector>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(JS_AutoIdVector))
+ );
}
impl Default for JS_AutoIdVector {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<JS_Base>() , 1usize , concat ! (
- "Size of template specialization: " , stringify ! ( JS_Base )
- ));
- assert_eq!(::std::mem::align_of::<JS_Base>() , 1usize , concat ! (
- "Alignment of template specialization: " , stringify ! (
- JS_Base ) ));
+ assert_eq!(
+ ::std::mem::size_of::<JS_Base>(),
+ 1usize,
+ concat!("Size of template specialization: ", stringify!(JS_Base))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<JS_Base>(),
+ 1usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(JS_Base)
+ )
+ );
}
diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs
index 50ea61e0..ba2ef976 100644
--- a/tests/expectations/tests/issue-573-layout-test-failures.rs
+++ b/tests/expectations/tests/issue-573-layout-test-failures.rs
@@ -10,30 +10,43 @@ pub struct Outer {
pub i: u8,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct AutoIdVector {
pub ar: Outer,
}
#[test]
fn bindgen_test_layout_AutoIdVector() {
- assert_eq!(::std::mem::size_of::<AutoIdVector>() , 1usize , concat ! (
- "Size of: " , stringify ! ( AutoIdVector ) ));
- assert_eq! (::std::mem::align_of::<AutoIdVector>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( AutoIdVector ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const AutoIdVector ) ) . ar as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( AutoIdVector ) , "::" ,
- stringify ! ( ar ) ));
-}
-impl Clone for AutoIdVector {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<AutoIdVector>(),
+ 1usize,
+ concat!("Size of: ", stringify!(AutoIdVector))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<AutoIdVector>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(AutoIdVector))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const AutoIdVector)).ar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(AutoIdVector),
+ "::",
+ stringify!(ar)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<Outer>() , 1usize , concat ! (
- "Size of template specialization: " , stringify ! ( Outer ) ));
- assert_eq!(::std::mem::align_of::<Outer>() , 1usize , concat ! (
- "Alignment of template specialization: " , stringify ! ( Outer
- ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Outer>(),
+ 1usize,
+ concat!("Size of template specialization: ", stringify!(Outer))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Outer>(),
+ 1usize,
+ concat!("Alignment of template specialization: ", stringify!(Outer))
+ );
}
diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs
index dd987b76..69a59d5a 100644
--- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs
+++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs
@@ -10,34 +10,47 @@ pub struct a {
pub _address: u8,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct _bindgen_ty_1 {
pub ar: a,
}
#[test]
fn bindgen_test_layout__bindgen_ty_1() {
- 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 {
- & ( * ( 0 as * const _bindgen_ty_1 ) ) . ar as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
- , stringify ! ( ar ) ));
-}
-impl Clone for _bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ 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 { &(*(0 as *const _bindgen_ty_1)).ar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(_bindgen_ty_1),
+ "::",
+ stringify!(ar)
+ )
+ );
}
extern "C" {
- #[link_name = "AutoIdVector"]
+ #[link_name = "\u{1}AutoIdVector"]
pub static mut AutoIdVector: _bindgen_ty_1;
}
#[test]
fn __bindgen_test_layout_a_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<a>() , 1usize , concat ! (
- "Size of template specialization: " , stringify ! ( a ) ));
- assert_eq!(::std::mem::align_of::<a>() , 1usize , concat ! (
- "Alignment of template specialization: " , stringify ! ( a )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 1usize,
+ concat!("Size of template specialization: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 1usize,
+ concat!("Alignment of template specialization: ", stringify!(a))
+ );
}
diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs
index d0ccacef..b6640998 100644
--- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs
+++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs
@@ -6,28 +6,33 @@
pub type RefPtr<T> = T;
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub _address: u8,
}
pub type A_a = b;
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
-}
-impl Clone for A {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 1usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(A))
+ );
}
#[repr(C)]
pub struct e<c> {
pub d: RefPtr<c>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<c>>,
}
-impl <c> Default for e<c> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<c> Default for e<c> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
@@ -40,17 +45,26 @@ pub struct g {
}
#[test]
fn bindgen_test_layout_g() {
- assert_eq!(::std::mem::size_of::<g>() , 1usize , concat ! (
- "Size of: " , stringify ! ( g ) ));
- assert_eq! (::std::mem::align_of::<g>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( g ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const g ) ) . h as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( g ) , "::" , stringify
- ! ( h ) ));
+ assert_eq!(
+ ::std::mem::size_of::<g>(),
+ 1usize,
+ concat!("Size of: ", stringify!(g))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<g>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(g))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const g)).h as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(g), "::", stringify!(h))
+ );
}
impl Default for g {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct b {
@@ -58,23 +72,36 @@ pub struct b {
}
#[test]
fn bindgen_test_layout_b() {
- assert_eq!(::std::mem::size_of::<b>() , 1usize , concat ! (
- "Size of: " , stringify ! ( b ) ));
- assert_eq! (::std::mem::align_of::<b>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<b>(),
+ 1usize,
+ concat!("Size of: ", stringify!(b))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<b>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(b))
+ );
}
impl Default for b {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_Z25Servo_Element_GetSnapshotv"]
+ #[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::<f>() , 1usize , concat ! (
- "Size of template specialization: " , stringify ! ( f ) ));
- assert_eq!(::std::mem::align_of::<f>() , 1usize , concat ! (
- "Alignment of template specialization: " , stringify ! ( f )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<f>(),
+ 1usize,
+ concat!("Size of template specialization: ", stringify!(f))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<f>(),
+ 1usize,
+ concat!("Alignment of template specialization: ", stringify!(f))
+ );
}
diff --git a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs
index 4bda0927..11571a2d 100644
--- a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs
+++ b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs
@@ -10,8 +10,10 @@ pub struct RefPtr<T> {
pub use_of_t: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for RefPtr<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for RefPtr<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -20,6 +22,8 @@ pub struct UsesRefPtrWithAliasedTypeParam<U> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
pub type UsesRefPtrWithAliasedTypeParam_V<U> = U;
-impl <U> Default for UsesRefPtrWithAliasedTypeParam<U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<U> Default for UsesRefPtrWithAliasedTypeParam<U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs
index e67400cc..91f76531 100644
--- a/tests/expectations/tests/issue-639-typedef-anon-field.rs
+++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs
@@ -5,77 +5,104 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub bar: Foo_Bar,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo_Bar {
pub abc: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Foo_Bar() {
- assert_eq!(::std::mem::size_of::<Foo_Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Foo_Bar ) ));
- assert_eq! (::std::mem::align_of::<Foo_Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Foo_Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo_Bar ) ) . abc as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo_Bar ) , "::" ,
- stringify ! ( abc ) ));
-}
-impl Clone for Foo_Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo_Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Foo_Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo_Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo_Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo_Bar)).abc as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo_Bar),
+ "::",
+ stringify!(abc)
+ )
+ );
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Baz {
pub _address: u8,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Baz_Bar {
pub abc: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Baz_Bar() {
- assert_eq!(::std::mem::size_of::<Baz_Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Baz_Bar ) ));
- assert_eq! (::std::mem::align_of::<Baz_Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Baz_Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Baz_Bar ) ) . abc as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Baz_Bar ) , "::" ,
- stringify ! ( abc ) ));
-}
-impl Clone for Baz_Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz_Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Baz_Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz_Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Baz_Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Baz_Bar)).abc as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Baz_Bar),
+ "::",
+ stringify!(abc)
+ )
+ );
}
#[test]
fn bindgen_test_layout_Baz() {
- assert_eq!(::std::mem::size_of::<Baz>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Baz ) ));
- assert_eq! (::std::mem::align_of::<Baz>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Baz ) ));
-}
-impl Clone for Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Baz))
+ );
}
diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs
index 82be5c92..ee5416e0 100644
--- a/tests/expectations/tests/issue-643-inner-struct.rs
+++ b/tests/expectations/tests/issue-643-inner-struct.rs
@@ -7,13 +7,15 @@
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
-impl <T> __IncompleteArrayField<T> {
+impl<T> __IncompleteArrayField<T> {
#[inline]
pub fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData)
}
#[inline]
- pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
#[inline]
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
::std::mem::transmute(self)
@@ -27,16 +29,18 @@ impl <T> __IncompleteArrayField<T> {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
-impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
-impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
#[repr(C)]
#[derive(Debug)]
pub struct rte_ring {
@@ -46,60 +50,81 @@ pub struct rte_ring {
pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct rte_ring_prod {
pub watermark: ::std::os::raw::c_uint,
}
#[test]
fn bindgen_test_layout_rte_ring_prod() {
- assert_eq!(::std::mem::size_of::<rte_ring_prod>() , 4usize , concat ! (
- "Size of: " , stringify ! ( rte_ring_prod ) ));
- assert_eq! (::std::mem::align_of::<rte_ring_prod>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ring_prod ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ring_prod ) ) . watermark as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
- , stringify ! ( watermark ) ));
-}
-impl Clone for rte_ring_prod {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ring_prod>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_ring_prod))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ring_prod>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ring_prod))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ring_prod)).watermark as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ring_prod),
+ "::",
+ stringify!(watermark)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[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() {
- assert_eq!(::std::mem::size_of::<rte_ring_cons>() , 4usize , concat ! (
- "Size of: " , stringify ! ( rte_ring_cons ) ));
- assert_eq! (::std::mem::align_of::<rte_ring_cons>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_ring_cons ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ring_cons ) ) . sc_dequeue as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
- , stringify ! ( sc_dequeue ) ));
-}
-impl Clone for rte_ring_cons {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_ring_cons>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_ring_cons))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ring_cons>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_ring_cons))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ring_cons)).sc_dequeue as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ring_cons),
+ "::",
+ stringify!(sc_dequeue)
+ )
+ );
}
#[test]
fn bindgen_test_layout_rte_ring() {
- assert_eq!(::std::mem::size_of::<rte_ring>() , 16usize , concat ! (
- "Size of: " , stringify ! ( rte_ring ) ));
- assert_eq! (::std::mem::align_of::<rte_ring>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( rte_ring ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ring>(),
+ 16usize,
+ concat!("Size of: ", stringify!(rte_ring))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_ring>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(rte_ring))
+ );
}
impl Default for rte_ring {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct rte_memzone {
pub _address: u8,
}
-impl Clone for rte_memzone {
- fn clone(&self) -> Self { *self }
-}
diff --git a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs
index 87228ec6..4d65c0ae 100644
--- a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs
+++ b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs
@@ -3,7 +3,8 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[derive(Clone, Copy, Debug)] pub struct RefPtr<T>(T);
+#[derive(Clone, Copy, Debug)]
+pub struct RefPtr<T>(T);
#[repr(C)]
pub struct HasRefPtr<T> {
@@ -11,6 +12,8 @@ pub struct HasRefPtr<T> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
pub type HasRefPtr_TypedefOfT<T> = T;
-impl <T> Default for HasRefPtr<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for HasRefPtr<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
index 27b5cfcd..a3d594e0 100644
--- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
+++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
@@ -10,7 +10,7 @@
/// up with the reight alignment, we're waiting on `#[repr(align="N")]` to land
/// in rustc).
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct NoDebug {
pub c: ::std::os::raw::c_char,
pub __bindgen_padding_0: [u8; 63usize],
@@ -33,22 +33,22 @@ fn bindgen_test_layout_NoDebug() {
)
);
}
-impl Clone for NoDebug {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for NoDebug {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
+impl ::std::cmp::PartialEq for NoDebug {
+ fn eq(&self, other: &NoDebug) -> bool {
+ self.c == other.c
+ }
+}
/// This should derive Debug/Hash/PartialEq/Eq because the padding size is less than the max derive
/// Debug/Hash/PartialEq/Eq impl for arrays. However, we conservatively don't derive Debug/Hash because
/// we determine Debug derive-ability before we compute padding, which happens at
/// codegen. (Again, we expect to get the alignment wrong for similar reasons.)
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct ShouldDeriveDebugButDoesNot {
pub c: [::std::os::raw::c_char; 32usize],
pub d: ::std::os::raw::c_char,
@@ -82,13 +82,13 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() {
)
);
}
-impl Clone for ShouldDeriveDebugButDoesNot {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for ShouldDeriveDebugButDoesNot {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
+impl ::std::cmp::PartialEq for ShouldDeriveDebugButDoesNot {
+ fn eq(&self, other: &ShouldDeriveDebugButDoesNot) -> bool {
+ self.c == other.c && self.d == other.d
+ }
+}
diff --git a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs
index 3e7c4195..f5ecbd5e 100644
--- a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs
+++ b/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs
@@ -10,8 +10,10 @@ pub struct RefPtr<T> {
pub a: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for RefPtr<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for RefPtr<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -19,8 +21,10 @@ pub struct nsMainThreadPtrHolder<T> {
pub a: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for nsMainThreadPtrHolder<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for nsMainThreadPtrHolder<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -28,6 +32,8 @@ pub struct nsMainThreadPtrHandle<T> {
pub mPtr: RefPtr<nsMainThreadPtrHolder<T>>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for nsMainThreadPtrHandle<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for nsMainThreadPtrHandle<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-662-part-2.rs b/tests/expectations/tests/issue-662-part-2.rs
index a1b97ca6..9e685b3a 100644
--- a/tests/expectations/tests/issue-662-part-2.rs
+++ b/tests/expectations/tests/issue-662-part-2.rs
@@ -3,7 +3,8 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[derive(Clone, Copy, Debug)] pub struct RefPtr<T>(T);
+#[derive(Clone, Copy, Debug)]
+pub struct RefPtr<T>(T);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -11,14 +12,18 @@ pub struct nsMainThreadPtrHolder<T> {
pub a: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for nsMainThreadPtrHolder<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for nsMainThreadPtrHolder<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct nsMainThreadPtrHandle<U> {
pub mPtr: RefPtr<nsMainThreadPtrHolder<U>>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
-impl <U> Default for nsMainThreadPtrHandle<U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<U> Default for nsMainThreadPtrHandle<U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs
index 31fe3c53..fc9ebc11 100644
--- a/tests/expectations/tests/issue-674-1.rs
+++ b/tests/expectations/tests/issue-674-1.rs
@@ -19,25 +19,31 @@ pub mod root {
pub type Maybe_ValueType<T> = T;
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct CapturingContentInfo {
pub a: u8,
}
#[test]
fn bindgen_test_layout_CapturingContentInfo() {
- assert_eq!(::std::mem::size_of::<CapturingContentInfo>() , 1usize ,
- concat ! (
- "Size of: " , stringify ! ( CapturingContentInfo ) ));
- assert_eq! (::std::mem::align_of::<CapturingContentInfo>() , 1usize ,
- concat ! (
- "Alignment of " , stringify ! ( CapturingContentInfo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const CapturingContentInfo ) ) . a as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- CapturingContentInfo ) , "::" , stringify ! ( a ) ));
- }
- impl Clone for CapturingContentInfo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<CapturingContentInfo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(CapturingContentInfo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<CapturingContentInfo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(CapturingContentInfo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const CapturingContentInfo)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(CapturingContentInfo),
+ "::",
+ stringify!(a)
+ )
+ );
}
}
diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs
index cfbef269..07c9cc4a 100644
--- a/tests/expectations/tests/issue-674-2.rs
+++ b/tests/expectations/tests/issue-674-2.rs
@@ -19,44 +19,50 @@ pub mod root {
pub type Rooted_ElementType<T> = T;
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct c {
pub b: u8,
}
#[test]
fn bindgen_test_layout_c() {
- assert_eq!(::std::mem::size_of::<c>() , 1usize , concat ! (
- "Size of: " , stringify ! ( c ) ));
- assert_eq! (::std::mem::align_of::<c>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( c ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const c ) ) . b as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( c ) , "::" ,
- stringify ! ( b ) ));
- }
- impl Clone for c {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<c>(),
+ 1usize,
+ concat!("Size of: ", stringify!(c))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<c>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(c))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const c)).b as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(c), "::", stringify!(b))
+ );
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct B {
pub a: root::c,
}
#[test]
fn bindgen_test_layout_B() {
- assert_eq!(::std::mem::size_of::<B>() , 1usize , concat ! (
- "Size of: " , stringify ! ( B ) ));
- assert_eq! (::std::mem::align_of::<B>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( B ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const B ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( B ) , "::" ,
- stringify ! ( a ) ));
- }
- impl Clone for B {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 1usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(B))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(B), "::", stringify!(a))
+ );
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
@@ -65,13 +71,21 @@ pub mod root {
}
#[test]
fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<root::StaticRefPtr>() , 1usize ,
- concat ! (
- "Size of template specialization: " , stringify ! (
- root::StaticRefPtr ) ));
- assert_eq!(::std::mem::align_of::<root::StaticRefPtr>() , 1usize ,
- concat ! (
- "Alignment of template specialization: " , stringify ! (
- root::StaticRefPtr ) ));
+ assert_eq!(
+ ::std::mem::size_of::<root::StaticRefPtr>(),
+ 1usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(root::StaticRefPtr)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<root::StaticRefPtr>(),
+ 1usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(root::StaticRefPtr)
+ )
+ );
}
}
diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs
index 71f794c3..1750cc0b 100644
--- a/tests/expectations/tests/issue-674-3.rs
+++ b/tests/expectations/tests/issue-674-3.rs
@@ -15,43 +15,54 @@ pub mod root {
}
pub type nsRefPtrHashtable_UserDataType<PtrType> = *mut PtrType;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct a {
pub b: u8,
}
#[test]
fn bindgen_test_layout_a() {
- assert_eq!(::std::mem::size_of::<a>() , 1usize , concat ! (
- "Size of: " , stringify ! ( a ) ));
- assert_eq! (::std::mem::align_of::<a>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const a ) ) . b as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( a ) , "::" ,
- stringify ! ( b ) ));
- }
- impl Clone for a {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 1usize,
+ concat!("Size of: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const a)).b as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(a), "::", stringify!(b))
+ );
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct nsCSSValue {
pub c: root::a,
}
#[test]
fn bindgen_test_layout_nsCSSValue() {
- assert_eq!(::std::mem::size_of::<nsCSSValue>() , 1usize , concat ! (
- "Size of: " , stringify ! ( nsCSSValue ) ));
- assert_eq! (::std::mem::align_of::<nsCSSValue>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( nsCSSValue ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsCSSValue ) ) . c as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsCSSValue ) , "::"
- , stringify ! ( c ) ));
- }
- impl Clone for nsCSSValue {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<nsCSSValue>(),
+ 1usize,
+ concat!("Size of: ", stringify!(nsCSSValue))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsCSSValue>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(nsCSSValue))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsCSSValue)).c as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsCSSValue),
+ "::",
+ stringify!(c)
+ )
+ );
}
}
diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs
index 09f5ee20..4878c1fa 100644
--- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs
+++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs
@@ -7,22 +7,27 @@
#[repr(C)]
pub struct VirtualMethods__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct VirtualMethods {
pub vtable_: *const VirtualMethods__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_VirtualMethods() {
- assert_eq!(::std::mem::size_of::<VirtualMethods>() , 8usize , concat ! (
- "Size of: " , stringify ! ( VirtualMethods ) ));
- assert_eq! (::std::mem::align_of::<VirtualMethods>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( VirtualMethods ) ));
-}
-impl Clone for VirtualMethods {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<VirtualMethods>(),
+ 8usize,
+ concat!("Size of: ", stringify!(VirtualMethods))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<VirtualMethods>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(VirtualMethods))
+ );
}
impl Default for VirtualMethods {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
@@ -30,31 +35,38 @@ pub struct Set {
pub bar: ::std::os::raw::c_int,
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct ServoElementSnapshotTable {
pub _base: Set,
}
#[test]
fn bindgen_test_layout_ServoElementSnapshotTable() {
- assert_eq!(::std::mem::size_of::<ServoElementSnapshotTable>() , 4usize ,
- concat ! (
- "Size of: " , stringify ! ( ServoElementSnapshotTable ) ));
- assert_eq! (::std::mem::align_of::<ServoElementSnapshotTable>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( ServoElementSnapshotTable )
- ));
-}
-impl Clone for ServoElementSnapshotTable {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ServoElementSnapshotTable>(),
+ 4usize,
+ concat!("Size of: ", stringify!(ServoElementSnapshotTable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ServoElementSnapshotTable>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ServoElementSnapshotTable))
+ );
}
impl Default for ServoElementSnapshotTable {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<Set>() , 4usize , concat ! (
- "Size of template specialization: " , stringify ! ( Set ) ));
- assert_eq!(::std::mem::align_of::<Set>() , 4usize , concat ! (
- "Alignment of template specialization: " , stringify ! ( Set )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<Set>(),
+ 4usize,
+ concat!("Size of template specialization: ", stringify!(Set))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Set>(),
+ 4usize,
+ concat!("Alignment of template specialization: ", stringify!(Set))
+ );
}
diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs
index 17e63981..96963ba5 100644
--- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs
+++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs
@@ -5,18 +5,21 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _bitfield_1: [u64; 4usize],
pub __bindgen_align: [u64; 0usize],
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 32usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 32usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs
index dbf21cf9..3dde6e73 100644
--- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs
+++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs
@@ -10,40 +10,47 @@ pub struct A {
_unused: [u8; 0],
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct B {
pub _bindgen_opaque_blob: u8,
}
#[test]
fn bindgen_test_layout_B() {
- assert_eq!(::std::mem::size_of::<B>() , 1usize , concat ! (
- "Size of: " , stringify ! ( B ) ));
- assert_eq! (::std::mem::align_of::<B>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( B ) ));
-}
-impl Clone for B {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 1usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(B))
+ );
}
extern "C" {
- #[link_name = "_ZN1B1aE"]
+ #[link_name = "\u{1}_ZN1B1aE"]
pub static mut B_a: A;
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct C {
pub b: B,
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 1usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . b as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( b ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 1usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).b as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(b))
+ );
}
diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs
index ed7d8a73..0807873b 100644
--- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs
+++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs
@@ -5,73 +5,85 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Pupper {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Pupper() {
- assert_eq!(::std::mem::size_of::<Pupper>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Pupper ) ));
- assert_eq! (::std::mem::align_of::<Pupper>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Pupper ) ));
-}
-impl Clone for Pupper {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Pupper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Pupper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Pupper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Pupper))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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::<Doggo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Doggo ) ));
- assert_eq! (::std::mem::align_of::<Doggo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Doggo ) ));
-}
-impl Clone for Doggo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Doggo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Doggo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Doggo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Doggo))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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::<SuchWow>() , 1usize , concat ! (
- "Size of: " , stringify ! ( SuchWow ) ));
- assert_eq! (::std::mem::align_of::<SuchWow>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( SuchWow ) ));
-}
-impl Clone for SuchWow {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<SuchWow>(),
+ 1usize,
+ concat!("Size of: ", stringify!(SuchWow))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<SuchWow>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(SuchWow))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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::<Opaque>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Opaque ) ));
- assert_eq! (::std::mem::align_of::<Opaque>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Opaque ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Opaque>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Opaque))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Opaque>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Opaque))
+ );
}
extern "C" {
- #[link_name = "_ZN6Opaque17eleven_out_of_tenEv"]
+ #[link_name = "\u{1}_ZN6Opaque17eleven_out_of_tenEv"]
pub fn Opaque_eleven_out_of_ten(this: *mut Opaque) -> SuchWow;
}
extern "C" {
- #[link_name = "_ZN6OpaqueC1E6Pupper"]
+ #[link_name = "\u{1}_ZN6OpaqueC1E6Pupper"]
pub fn Opaque_Opaque(this: *mut Opaque, pup: Pupper);
}
-impl Clone for Opaque {
- fn clone(&self) -> Self { *self }
-}
impl Opaque {
#[inline]
pub unsafe fn eleven_out_of_ten(&mut self) -> SuchWow {
@@ -85,26 +97,34 @@ impl Opaque {
}
}
extern "C" {
- #[link_name = "_ZN6Opaque11MAJESTIC_AFE"]
+ #[link_name = "\u{1}_ZN6Opaque11MAJESTIC_AFE"]
pub static mut Opaque_MAJESTIC_AF: Doggo;
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Whitelisted {
pub some_member: Opaque,
}
#[test]
fn bindgen_test_layout_Whitelisted() {
- assert_eq!(::std::mem::size_of::<Whitelisted>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Whitelisted ) ));
- assert_eq! (::std::mem::align_of::<Whitelisted>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Whitelisted ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Whitelisted ) ) . some_member as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Whitelisted ) , "::" ,
- stringify ! ( some_member ) ));
-}
-impl Clone for Whitelisted {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Whitelisted>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Whitelisted))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Whitelisted>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Whitelisted))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Whitelisted)).some_member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Whitelisted),
+ "::",
+ stringify!(some_member)
+ )
+ );
}
diff --git a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs
index c894b95c..36cae722 100644
--- a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs
+++ b/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs
@@ -5,17 +5,20 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/issue-833-1.rs b/tests/expectations/tests/issue-833-1.rs
index 4900bf2d..aa19dd1b 100644
--- a/tests/expectations/tests/issue-833-1.rs
+++ b/tests/expectations/tests/issue-833-1.rs
@@ -3,7 +3,10 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[repr(C)] pub struct nsTArray { pub hdr: *const () }
+#[repr(C)]
+pub struct nsTArray {
+ pub hdr: *const (),
+}
extern "C" {
pub fn func() -> *mut nsTArray;
diff --git a/tests/expectations/tests/issue-833.rs b/tests/expectations/tests/issue-833.rs
index 9de7c64f..4ee4602a 100644
--- a/tests/expectations/tests/issue-833.rs
+++ b/tests/expectations/tests/issue-833.rs
@@ -3,7 +3,10 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[repr(C)] pub struct nsTArray<T> { pub hdr: *const T }
+#[repr(C)]
+pub struct nsTArray<T> {
+ pub hdr: *const T,
+}
extern "C" {
pub fn func() -> *mut nsTArray<::std::os::raw::c_int>;
diff --git a/tests/expectations/tests/issue-834.rs b/tests/expectations/tests/issue-834.rs
index 1e507ad2..a8014fb9 100644
--- a/tests/expectations/tests/issue-834.rs
+++ b/tests/expectations/tests/issue-834.rs
@@ -5,17 +5,20 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct U {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_U() {
- assert_eq!(::std::mem::size_of::<U>() , 1usize , concat ! (
- "Size of: " , stringify ! ( U ) ));
- assert_eq! (::std::mem::align_of::<U>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( U ) ));
-}
-impl Clone for U {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<U>(),
+ 1usize,
+ concat!("Size of: ", stringify!(U))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<U>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(U))
+ );
}
diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs
index e0330d5f..61cbfc3a 100644
--- a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs
+++ b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs
@@ -12,25 +12,28 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Type {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN6Halide4Type1bE"]
+ #[link_name = "\u{1}_ZN6Halide4Type1bE"]
pub static mut Type_b: root::a;
}
#[test]
fn bindgen_test_layout_Type() {
- assert_eq!(::std::mem::size_of::<Type>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Type ) ));
- assert_eq! (::std::mem::align_of::<Type>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Type ) ));
- }
- impl Clone for Type {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Type>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Type))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Type>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Type))
+ );
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
- pub enum a { }
+ pub enum a {}
}
diff --git a/tests/expectations/tests/issue_311.rs b/tests/expectations/tests/issue_311.rs
index c5ecb966..b8575378 100644
--- a/tests/expectations/tests/issue_311.rs
+++ b/tests/expectations/tests/issue_311.rs
@@ -9,37 +9,39 @@ pub mod root {
#[allow(unused_imports)]
use self::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct jsval_layout {
pub __bindgen_anon_1: root::jsval_layout__bindgen_ty_1,
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
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::<jsval_layout__bindgen_ty_1>() ,
- 1usize , concat ! (
- "Size of: " , stringify ! ( jsval_layout__bindgen_ty_1 )
- ));
- assert_eq! (::std::mem::align_of::<jsval_layout__bindgen_ty_1>() ,
- 1usize , concat ! (
- "Alignment of " , stringify ! ( jsval_layout__bindgen_ty_1
- ) ));
- }
- impl Clone for jsval_layout__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<jsval_layout__bindgen_ty_1>(),
+ 1usize,
+ concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<jsval_layout__bindgen_ty_1>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1))
+ );
}
#[test]
fn bindgen_test_layout_jsval_layout() {
- assert_eq!(::std::mem::size_of::<jsval_layout>() , 1usize , concat ! (
- "Size of: " , stringify ! ( jsval_layout ) ));
- assert_eq! (::std::mem::align_of::<jsval_layout>() , 1usize , concat !
- ( "Alignment of " , stringify ! ( jsval_layout ) ));
- }
- impl Clone for jsval_layout {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<jsval_layout>(),
+ 1usize,
+ concat!("Size of: ", stringify!(jsval_layout))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<jsval_layout>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(jsval_layout))
+ );
}
}
diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs
index 2e93bb46..a422ffc0 100644
--- a/tests/expectations/tests/jsval_layout_opaque.rs
+++ b/tests/expectations/tests/jsval_layout_opaque.rs
@@ -72,7 +72,7 @@ pub enum JSWhyMagic {
JS_WHY_MAGIC_COUNT = 18,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union jsval_layout {
pub asBits: u64,
pub debugView: jsval_layout__bindgen_ty_1,
@@ -84,7 +84,7 @@ pub union jsval_layout {
_bindgen_union_align: u64,
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct jsval_layout__bindgen_ty_1 {
pub _bitfield_1: u64,
pub __bindgen_align: [u64; 0usize],
@@ -102,11 +102,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_1() {
concat!("Alignment of ", stringify!(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 { ::std::mem::zeroed() }
@@ -123,13 +118,13 @@ impl jsval_layout__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 140737488355327u64 as u64;
+ let mask = 0x7fffffffffff as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_payload47(&mut self, val: u64) {
- let mask = 140737488355327u64 as u64;
+ let mask = 0x7fffffffffff as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -159,13 +154,13 @@ impl jsval_layout__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 18446603336221196288u64 as u64;
+ let mask = 0xffff800000000000 as u64;
let val = (unit_field_val & mask) >> 47usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_tag(&mut self, val: JSValueTag) {
- let mask = 18446603336221196288u64 as u64;
+ let mask = 0xffff800000000000 as u64;
let val = val as u32 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -187,17 +182,17 @@ impl jsval_layout__bindgen_ty_1 {
}
#[inline]
pub fn new_bitfield_1(payload47: u64, tag: JSValueTag) -> u64 {
- ((0 | ((payload47 as u64 as u64) << 0usize) & (140737488355327u64 as u64)) |
- ((tag as u32 as u64) << 47usize) & (18446603336221196288u64 as u64))
+ ((0 | ((payload47 as u64 as u64) << 0usize) & (0x7fffffffffff as u64))
+ | ((tag as u32 as u64) << 47usize) & (0xffff800000000000 as u64))
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct jsval_layout__bindgen_ty_2 {
pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 {
pub i32: i32,
pub u32: u32,
@@ -259,11 +254,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() {
)
);
}
-impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -292,11 +282,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() {
)
);
}
-impl Clone for jsval_layout__bindgen_ty_2 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for jsval_layout__bindgen_ty_2 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -385,18 +370,13 @@ fn bindgen_test_layout_jsval_layout() {
)
);
}
-impl Clone for jsval_layout {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for jsval_layout {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct Value {
pub data: jsval_layout,
}
@@ -423,11 +403,6 @@ fn bindgen_test_layout_Value() {
)
);
}
-impl Clone for Value {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for Value {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs
index b818bf90..93a549c5 100644
--- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs
+++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs
@@ -46,7 +46,7 @@ impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
true
}
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47;
pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327;
pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328;
@@ -166,13 +166,13 @@ impl jsval_layout__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 140737488355327u64 as u64;
+ let mask = 0x7fffffffffff as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_payload47(&mut self, val: u64) {
- let mask = 140737488355327u64 as u64;
+ let mask = 0x7fffffffffff as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -202,13 +202,13 @@ impl jsval_layout__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 18446603336221196288u64 as u64;
+ let mask = 0xffff800000000000 as u64;
let val = (unit_field_val & mask) >> 47usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_tag(&mut self, val: JSValueTag) {
- let mask = 18446603336221196288u64 as u64;
+ let mask = 0xffff800000000000 as u64;
let val = val as u32 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -230,8 +230,8 @@ impl jsval_layout__bindgen_ty_1 {
}
#[inline]
pub fn new_bitfield_1(payload47: u64, tag: JSValueTag) -> u64 {
- ((0 | ((payload47 as u64 as u64) << 0usize) & (140737488355327u64 as u64)) |
- ((tag as u32 as u64) << 47usize) & (18446603336221196288u64 as u64))
+ ((0 | ((payload47 as u64 as u64) << 0usize) & (0x7fffffffffff as u64))
+ | ((tag as u32 as u64) << 47usize) & (0xffff800000000000 as u64))
}
}
#[repr(C)]
diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs
index 037a8d80..b354f431 100644
--- a/tests/expectations/tests/keywords.rs
+++ b/tests/expectations/tests/keywords.rs
@@ -5,198 +5,198 @@
extern "C" {
- #[link_name = "u8"]
+ #[link_name = "\u{1}u8"]
pub static mut u8: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "u16"]
+ #[link_name = "\u{1}u16"]
pub static mut u16: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "u32"]
+ #[link_name = "\u{1}u32"]
pub static mut u32: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "u64"]
+ #[link_name = "\u{1}u64"]
pub static mut u64: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "i8"]
+ #[link_name = "\u{1}i8"]
pub static mut i8: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "i16"]
+ #[link_name = "\u{1}i16"]
pub static mut i16: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "i32"]
+ #[link_name = "\u{1}i32"]
pub static mut i32: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "i64"]
+ #[link_name = "\u{1}i64"]
pub static mut i64: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "f32"]
+ #[link_name = "\u{1}f32"]
pub static mut f32: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "f64"]
+ #[link_name = "\u{1}f64"]
pub static mut f64: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "usize"]
+ #[link_name = "\u{1}usize"]
pub static mut usize: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "isize"]
+ #[link_name = "\u{1}isize"]
pub static mut isize: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "as"]
+ #[link_name = "\u{1}as"]
pub static mut as_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "box"]
+ #[link_name = "\u{1}box"]
pub static mut box_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "crate"]
+ #[link_name = "\u{1}crate"]
pub static mut crate_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "false"]
+ #[link_name = "\u{1}false"]
pub static mut false_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "fn"]
+ #[link_name = "\u{1}fn"]
pub static mut fn_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "impl"]
+ #[link_name = "\u{1}impl"]
pub static mut impl_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "in"]
+ #[link_name = "\u{1}in"]
pub static mut in_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "let"]
+ #[link_name = "\u{1}let"]
pub static mut let_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "loop"]
+ #[link_name = "\u{1}loop"]
pub static mut loop_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "match"]
+ #[link_name = "\u{1}match"]
pub static mut match_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "mod"]
+ #[link_name = "\u{1}mod"]
pub static mut mod_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "move"]
+ #[link_name = "\u{1}move"]
pub static mut move_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "mut"]
+ #[link_name = "\u{1}mut"]
pub static mut mut_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "pub"]
+ #[link_name = "\u{1}pub"]
pub static mut pub_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "ref"]
+ #[link_name = "\u{1}ref"]
pub static mut ref_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "self"]
+ #[link_name = "\u{1}self"]
pub static mut self_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "Self"]
+ #[link_name = "\u{1}Self"]
pub static mut Self_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "super"]
+ #[link_name = "\u{1}super"]
pub static mut super_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "trait"]
+ #[link_name = "\u{1}trait"]
pub static mut trait_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "true"]
+ #[link_name = "\u{1}true"]
pub static mut true_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "type"]
+ #[link_name = "\u{1}type"]
pub static mut type_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "unsafe"]
+ #[link_name = "\u{1}unsafe"]
pub static mut unsafe_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "use"]
+ #[link_name = "\u{1}use"]
pub static mut use_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "where"]
+ #[link_name = "\u{1}where"]
pub static mut where_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "abstract"]
+ #[link_name = "\u{1}abstract"]
pub static mut abstract_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "alignof"]
+ #[link_name = "\u{1}alignof"]
pub static mut alignof_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "become"]
+ #[link_name = "\u{1}become"]
pub static mut become_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "final"]
+ #[link_name = "\u{1}final"]
pub static mut final_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "macro"]
+ #[link_name = "\u{1}macro"]
pub static mut macro_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "offsetof"]
+ #[link_name = "\u{1}offsetof"]
pub static mut offsetof_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "override"]
+ #[link_name = "\u{1}override"]
pub static mut override_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "priv"]
+ #[link_name = "\u{1}priv"]
pub static mut priv_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "proc"]
+ #[link_name = "\u{1}proc"]
pub static mut proc_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "pure"]
+ #[link_name = "\u{1}pure"]
pub static mut pure_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "unsized"]
+ #[link_name = "\u{1}unsized"]
pub static mut unsized_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "virtual"]
+ #[link_name = "\u{1}virtual"]
pub static mut virtual_: ::std::os::raw::c_int;
}
extern "C" {
- #[link_name = "yield"]
+ #[link_name = "\u{1}yield"]
pub static mut yield_: ::std::os::raw::c_int;
}
diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs
index 28ebdc76..eedf1e2b 100644
--- a/tests/expectations/tests/layout.rs
+++ b/tests/expectations/tests/layout.rs
@@ -7,13 +7,15 @@
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
-impl <T> __IncompleteArrayField<T> {
+impl<T> __IncompleteArrayField<T> {
#[inline]
pub fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData)
}
#[inline]
- pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
#[inline]
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
::std::mem::transmute(self)
@@ -27,16 +29,18 @@ impl <T> __IncompleteArrayField<T> {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
-impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
-impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
#[repr(C, packed)]
#[derive(Debug, Default)]
pub struct header {
@@ -47,6 +51,9 @@ pub struct header {
}
#[test]
fn bindgen_test_layout_header() {
- assert_eq!(::std::mem::size_of::<header>() , 16usize , concat ! (
- "Size of: " , stringify ! ( header ) ));
+ assert_eq!(
+ ::std::mem::size_of::<header>(),
+ 16usize,
+ concat!("Size of: ", stringify!(header))
+ );
}
diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs
index 9e9ac872..859416d7 100644
--- a/tests/expectations/tests/layout_align.rs
+++ b/tests/expectations/tests/layout_align.rs
@@ -75,7 +75,7 @@ impl Default for rte_kni_fifo {
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct rte_eth_link {
/// < ETH_SPEED_NUM_
pub link_speed: u32,
@@ -106,11 +106,6 @@ fn bindgen_test_layout_rte_eth_link() {
)
);
}
-impl Clone for rte_eth_link {
- fn clone(&self) -> Self {
- *self
- }
-}
impl rte_eth_link {
#[inline]
pub fn link_duplex(&self) -> u16 {
@@ -122,13 +117,13 @@ impl rte_eth_link {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_link_duplex(&mut self, val: u16) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -158,13 +153,13 @@ impl rte_eth_link {
::std::mem::size_of::<u8>(),
)
};
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_link_autoneg(&mut self, val: u16) {
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -194,13 +189,13 @@ impl rte_eth_link {
::std::mem::size_of::<u8>(),
)
};
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_link_status(&mut self, val: u16) {
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -222,8 +217,8 @@ impl rte_eth_link {
}
#[inline]
pub fn new_bitfield_1(link_duplex: u16, link_autoneg: u16, link_status: u16) -> u8 {
- (((0 | ((link_duplex as u16 as u8) << 0usize) & (1u64 as u8)) |
- ((link_autoneg as u16 as u8) << 1usize) & (2u64 as u8)) |
- ((link_status as u16 as u8) << 2usize) & (4u64 as u8))
+ (((0 | ((link_duplex as u16 as u8) << 0usize) & (0x1 as u8))
+ | ((link_autoneg as u16 as u8) << 1usize) & (0x2 as u8))
+ | ((link_status as u16 as u8) << 2usize) & (0x4 as u8))
}
}
diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs
index 8f853068..d49a870b 100644
--- a/tests/expectations/tests/layout_arp.rs
+++ b/tests/expectations/tests/layout_arp.rs
@@ -22,29 +22,37 @@ pub const ARP_OP_INVREPLY: ::std::os::raw::c_uint = 9;
/// administrator and does not contain OUIs.
/// See http://standards.ieee.org/regauth/groupmac/tutorial.html
#[repr(C, packed)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct ether_addr {
/// < Addr bytes in tx order
pub addr_bytes: [u8; 6usize],
}
#[test]
fn bindgen_test_layout_ether_addr() {
- assert_eq!(::std::mem::size_of::<ether_addr>() , 6usize , concat ! (
- "Size of: " , stringify ! ( ether_addr ) ));
- assert_eq! (::std::mem::align_of::<ether_addr>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( ether_addr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ether_addr ) ) . addr_bytes as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ether_addr ) , "::" ,
- stringify ! ( addr_bytes ) ));
-}
-impl Clone for ether_addr {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ether_addr>(),
+ 6usize,
+ concat!("Size of: ", stringify!(ether_addr))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ether_addr>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(ether_addr))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ether_addr)).addr_bytes as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ether_addr),
+ "::",
+ stringify!(addr_bytes)
+ )
+ );
}
/// ARP header IPv4 payload.
#[repr(C, packed)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct arp_ipv4 {
/// < sender hardware address
pub arp_sha: ether_addr,
@@ -57,37 +65,60 @@ pub struct arp_ipv4 {
}
#[test]
fn bindgen_test_layout_arp_ipv4() {
- assert_eq!(::std::mem::size_of::<arp_ipv4>() , 20usize , concat ! (
- "Size of: " , stringify ! ( arp_ipv4 ) ));
- assert_eq! (::std::mem::align_of::<arp_ipv4>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( arp_ipv4 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_ipv4 ) ) . arp_sha as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" ,
- stringify ! ( arp_sha ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_ipv4 ) ) . arp_sip as * const _ as
- usize } , 6usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" ,
- stringify ! ( arp_sip ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_ipv4 ) ) . arp_tha as * const _ as
- usize } , 10usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" ,
- stringify ! ( arp_tha ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_ipv4 ) ) . arp_tip as * const _ as
- usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" ,
- stringify ! ( arp_tip ) ));
-}
-impl Clone for arp_ipv4 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<arp_ipv4>(),
+ 20usize,
+ concat!("Size of: ", stringify!(arp_ipv4))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<arp_ipv4>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(arp_ipv4))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_ipv4)).arp_sha as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_ipv4),
+ "::",
+ stringify!(arp_sha)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_ipv4)).arp_sip as *const _ as usize },
+ 6usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_ipv4),
+ "::",
+ stringify!(arp_sip)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_ipv4)).arp_tha as *const _ as usize },
+ 10usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_ipv4),
+ "::",
+ stringify!(arp_tha)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_ipv4)).arp_tip as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_ipv4),
+ "::",
+ stringify!(arp_tip)
+ )
+ );
}
/// ARP header.
#[repr(C, packed)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct arp_hdr {
pub arp_hrd: u16,
pub arp_pro: u16,
@@ -98,41 +129,74 @@ pub struct arp_hdr {
}
#[test]
fn bindgen_test_layout_arp_hdr() {
- assert_eq!(::std::mem::size_of::<arp_hdr>() , 28usize , concat ! (
- "Size of: " , stringify ! ( arp_hdr ) ));
- assert_eq! (::std::mem::align_of::<arp_hdr>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( arp_hdr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_hdr ) ) . arp_hrd as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_hdr ) , "::" ,
- stringify ! ( arp_hrd ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_hdr ) ) . arp_pro as * const _ as
- usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_hdr ) , "::" ,
- stringify ! ( arp_pro ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_hdr ) ) . arp_hln as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_hdr ) , "::" ,
- stringify ! ( arp_hln ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_hdr ) ) . arp_pln as * const _ as
- usize } , 5usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_hdr ) , "::" ,
- stringify ! ( arp_pln ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_hdr ) ) . arp_op as * const _ as
- usize } , 6usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_hdr ) , "::" ,
- stringify ! ( arp_op ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const arp_hdr ) ) . arp_data as * const _ as
- usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( arp_hdr ) , "::" ,
- stringify ! ( arp_data ) ));
-}
-impl Clone for arp_hdr {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<arp_hdr>(),
+ 28usize,
+ concat!("Size of: ", stringify!(arp_hdr))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<arp_hdr>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(arp_hdr))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_hdr)).arp_hrd as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_hdr),
+ "::",
+ stringify!(arp_hrd)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_hdr)).arp_pro as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_hdr),
+ "::",
+ stringify!(arp_pro)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_hdr)).arp_hln as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_hdr),
+ "::",
+ stringify!(arp_hln)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_hdr)).arp_pln as *const _ as usize },
+ 5usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_hdr),
+ "::",
+ stringify!(arp_pln)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_hdr)).arp_op as *const _ as usize },
+ 6usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_hdr),
+ "::",
+ stringify!(arp_op)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const arp_hdr)).arp_data as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(arp_hdr),
+ "::",
+ stringify!(arp_data)
+ )
+ );
}
diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs
index 9f2082ec..7dcd507a 100644
--- a/tests/expectations/tests/layout_array.rs
+++ b/tests/expectations/tests/layout_array.rs
@@ -21,33 +21,35 @@ pub struct rte_mempool {
/// it will most likely point to a different type of data structure, and
/// will be transparent to the application programmer.
/// This function should set mp->pool_data.
-pub type rte_mempool_alloc_t =
- ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool)
- -> ::std::os::raw::c_int>;
+pub type rte_mempool_alloc_t = ::std::option::Option<
+ unsafe extern "C" fn(mp: *mut rte_mempool) -> ::std::os::raw::c_int,
+>;
/// Free the opaque private data pointed to by mp->pool_data pointer.
-pub type rte_mempool_free_t =
- ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool)>;
+pub type rte_mempool_free_t = ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool)>;
/// Enqueue an object into the external pool.
-pub type rte_mempool_enqueue_t =
- ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool,
- obj_table:
- *const *const ::std::os::raw::c_void,
- n: ::std::os::raw::c_uint)
- -> ::std::os::raw::c_int>;
+pub type rte_mempool_enqueue_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ mp: *mut rte_mempool,
+ obj_table: *const *const ::std::os::raw::c_void,
+ n: ::std::os::raw::c_uint,
+ ) -> ::std::os::raw::c_int,
+>;
/// Dequeue an object from the external pool.
-pub type rte_mempool_dequeue_t =
- ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool,
- obj_table:
- *mut *mut ::std::os::raw::c_void,
- n: ::std::os::raw::c_uint)
- -> ::std::os::raw::c_int>;
+pub type rte_mempool_dequeue_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ mp: *mut rte_mempool,
+ obj_table: *mut *mut ::std::os::raw::c_void,
+ n: ::std::os::raw::c_uint,
+ ) -> ::std::os::raw::c_int,
+>;
/// Return the number of available objects in the external pool.
-pub type rte_mempool_get_count =
- ::std::option::Option<unsafe extern "C" fn(mp: *const rte_mempool)
- -> ::std::os::raw::c_uint>;
+pub type rte_mempool_get_count = ::std::option::Option<
+ unsafe extern "C" fn(mp: *const rte_mempool)
+ -> ::std::os::raw::c_uint,
+>;
/// Structure defining mempool operations structure
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct rte_mempool_ops {
/// < Name of mempool ops struct.
pub name: [::std::os::raw::c_char; 32usize],
@@ -65,66 +67,113 @@ pub struct rte_mempool_ops {
}
#[test]
fn bindgen_test_layout_rte_mempool_ops() {
- assert_eq!(::std::mem::size_of::<rte_mempool_ops>() , 128usize , concat !
- ( "Size of: " , stringify ! ( rte_mempool_ops ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops ) ) . name as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops ) ,
- "::" , stringify ! ( name ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops ) ) . alloc as * const _
- as usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops ) ,
- "::" , stringify ! ( alloc ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops ) ) . free as * const _
- as usize } , 40usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops ) ,
- "::" , stringify ! ( free ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops ) ) . enqueue as * const
- _ as usize } , 48usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops ) ,
- "::" , stringify ! ( enqueue ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops ) ) . dequeue as * const
- _ as usize } , 56usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops ) ,
- "::" , stringify ! ( dequeue ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops ) ) . get_count as *
- const _ as usize } , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops ) ,
- "::" , stringify ! ( get_count ) ));
-}
-impl Clone for rte_mempool_ops {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_mempool_ops>(),
+ 128usize,
+ concat!("Size of: ", stringify!(rte_mempool_ops))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops)).name as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops),
+ "::",
+ stringify!(name)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops)).alloc as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops),
+ "::",
+ stringify!(alloc)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops)).free as *const _ as usize },
+ 40usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops),
+ "::",
+ stringify!(free)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops)).enqueue as *const _ as usize },
+ 48usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops),
+ "::",
+ stringify!(enqueue)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops)).dequeue as *const _ as usize },
+ 56usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops),
+ "::",
+ stringify!(dequeue)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops)).get_count as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops),
+ "::",
+ stringify!(get_count)
+ )
+ );
}
impl Default for rte_mempool_ops {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for rte_mempool_ops {
+ fn eq(&self, other: &rte_mempool_ops) -> bool {
+ self.name == other.name && self.alloc == other.alloc && self.free == other.free
+ && self.enqueue == other.enqueue && self.dequeue == other.dequeue
+ && self.get_count == other.get_count
+ }
}
/// The rte_spinlock_t type.
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_spinlock_t {
/// < lock status 0 = unlocked, 1 = locked
pub locked: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_rte_spinlock_t() {
- assert_eq!(::std::mem::size_of::<rte_spinlock_t>() , 4usize , concat ! (
- "Size of: " , stringify ! ( rte_spinlock_t ) ));
- assert_eq! (::std::mem::align_of::<rte_spinlock_t>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( rte_spinlock_t ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_spinlock_t ) ) . locked as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_spinlock_t ) , "::"
- , stringify ! ( locked ) ));
-}
-impl Clone for rte_spinlock_t {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_spinlock_t>(),
+ 4usize,
+ concat!("Size of: ", stringify!(rte_spinlock_t))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<rte_spinlock_t>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(rte_spinlock_t))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_spinlock_t)).locked as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_spinlock_t),
+ "::",
+ stringify!(locked)
+ )
+ );
}
/// Structure storing the table of registered ops structs, each of which contain
/// the function pointers for the mempool ops functions.
@@ -134,7 +183,7 @@ impl Clone for rte_spinlock_t {
/// any function pointers stored directly in the mempool struct would not be.
/// This results in us simply having "ops_index" in the mempool struct.
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct rte_mempool_ops_table {
/// < Spinlock for add/delete.
pub sl: rte_spinlock_t,
@@ -146,34 +195,50 @@ pub struct rte_mempool_ops_table {
}
#[test]
fn bindgen_test_layout_rte_mempool_ops_table() {
- assert_eq!(::std::mem::size_of::<rte_mempool_ops_table>() , 2112usize ,
- concat ! ( "Size of: " , stringify ! ( rte_mempool_ops_table )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops_table ) ) . sl as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops_table )
- , "::" , stringify ! ( sl ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops_table ) ) . num_ops as *
- const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops_table )
- , "::" , stringify ! ( num_ops ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_mempool_ops_table ) ) . ops as *
- const _ as usize } , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_mempool_ops_table )
- , "::" , stringify ! ( ops ) ));
-}
-impl Clone for rte_mempool_ops_table {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_mempool_ops_table>(),
+ 2112usize,
+ concat!("Size of: ", stringify!(rte_mempool_ops_table))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops_table)).sl as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops_table),
+ "::",
+ stringify!(sl)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops_table)).num_ops as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops_table),
+ "::",
+ stringify!(num_ops)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_mempool_ops_table)).ops as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_mempool_ops_table),
+ "::",
+ stringify!(ops)
+ )
+ );
}
impl Default for rte_mempool_ops_table {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
/// Structure to hold malloc heap
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct malloc_heap {
pub lock: rte_spinlock_t,
pub free_head: [malloc_heap__bindgen_ty_1; 13usize],
@@ -181,68 +246,99 @@ pub struct malloc_heap {
pub total_size: usize,
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct malloc_heap__bindgen_ty_1 {
pub lh_first: *mut malloc_elem,
}
#[test]
fn bindgen_test_layout_malloc_heap__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<malloc_heap__bindgen_ty_1>() , 8usize ,
- concat ! (
- "Size of: " , stringify ! ( malloc_heap__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<malloc_heap__bindgen_ty_1>() , 8usize ,
- concat ! (
- "Alignment of " , stringify ! ( malloc_heap__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const malloc_heap__bindgen_ty_1 ) ) . lh_first
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- malloc_heap__bindgen_ty_1 ) , "::" , stringify ! ( lh_first )
- ));
-}
-impl Clone for malloc_heap__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<malloc_heap__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(malloc_heap__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<malloc_heap__bindgen_ty_1>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const malloc_heap__bindgen_ty_1)).lh_first as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(malloc_heap__bindgen_ty_1),
+ "::",
+ stringify!(lh_first)
+ )
+ );
}
impl Default for malloc_heap__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_malloc_heap() {
- assert_eq!(::std::mem::size_of::<malloc_heap>() , 128usize , concat ! (
- "Size of: " , stringify ! ( malloc_heap ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const malloc_heap ) ) . lock as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( malloc_heap ) , "::" ,
- stringify ! ( lock ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const malloc_heap ) ) . free_head as * const _
- as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( malloc_heap ) , "::" ,
- stringify ! ( free_head ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const malloc_heap ) ) . alloc_count as * const
- _ as usize } , 112usize , concat ! (
- "Alignment of field: " , stringify ! ( malloc_heap ) , "::" ,
- stringify ! ( alloc_count ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const malloc_heap ) ) . total_size as * const _
- as usize } , 120usize , concat ! (
- "Alignment of field: " , stringify ! ( malloc_heap ) , "::" ,
- stringify ! ( total_size ) ));
-}
-impl Clone for malloc_heap {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<malloc_heap>(),
+ 128usize,
+ concat!("Size of: ", stringify!(malloc_heap))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const malloc_heap)).lock as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(malloc_heap),
+ "::",
+ stringify!(lock)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const malloc_heap)).free_head as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(malloc_heap),
+ "::",
+ stringify!(free_head)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const malloc_heap)).alloc_count as *const _ as usize },
+ 112usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(malloc_heap),
+ "::",
+ stringify!(alloc_count)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const malloc_heap)).total_size as *const _ as usize },
+ 120usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(malloc_heap),
+ "::",
+ stringify!(total_size)
+ )
+ );
}
impl Default for malloc_heap {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for malloc_heap {
+ fn eq(&self, other: &malloc_heap) -> bool {
+ self.lock == other.lock && self.free_head == other.free_head
+ && self.alloc_count == other.alloc_count && self.total_size == other.total_size
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct malloc_elem {
pub _address: u8,
}
-impl Clone for malloc_elem {
- fn clone(&self) -> Self { *self }
-}
diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs
index 1a3da41e..6c8ec850 100644
--- a/tests/expectations/tests/layout_array_too_long.rs
+++ b/tests/expectations/tests/layout_array_too_long.rs
@@ -20,7 +20,7 @@ pub enum _bindgen_ty_1 {
}
/// @internal fragmented mbuf
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ip_frag {
/// < offset into the packet
pub ofs: u16,
@@ -31,35 +31,55 @@ pub struct ip_frag {
}
#[test]
fn bindgen_test_layout_ip_frag() {
- assert_eq!(::std::mem::size_of::<ip_frag>() , 16usize , concat ! (
- "Size of: " , stringify ! ( ip_frag ) ));
- assert_eq! (::std::mem::align_of::<ip_frag>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ip_frag ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag ) ) . ofs as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag ) , "::" ,
- stringify ! ( ofs ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag ) ) . len as * const _ as usize }
- , 2usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag ) , "::" ,
- stringify ! ( len ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag ) ) . mb as * const _ as usize }
- , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag ) , "::" ,
- stringify ! ( mb ) ));
-}
-impl Clone for ip_frag {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag>(),
+ 16usize,
+ concat!("Size of: ", stringify!(ip_frag))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_frag>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_frag))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag)).ofs as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag),
+ "::",
+ stringify!(ofs)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag)).len as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag),
+ "::",
+ stringify!(len)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag)).mb as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag),
+ "::",
+ stringify!(mb)
+ )
+ );
}
impl Default for ip_frag {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
/// @internal <src addr, dst_addr, id> to uniquely indetify fragmented datagram.
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ip_frag_key {
/// < src address, first 8 bytes used for IPv4
pub src_dst: [u64; 4usize],
@@ -70,33 +90,51 @@ pub struct ip_frag_key {
}
#[test]
fn bindgen_test_layout_ip_frag_key() {
- assert_eq!(::std::mem::size_of::<ip_frag_key>() , 40usize , concat ! (
- "Size of: " , stringify ! ( ip_frag_key ) ));
- assert_eq! (::std::mem::align_of::<ip_frag_key>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ip_frag_key ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_key ) ) . src_dst as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" ,
- stringify ! ( src_dst ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_key ) ) . id as * const _ as
- usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" ,
- stringify ! ( id ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_key ) ) . key_len as * const _ as
- usize } , 36usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" ,
- stringify ! ( key_len ) ));
-}
-impl Clone for ip_frag_key {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_key>(),
+ 40usize,
+ concat!("Size of: ", stringify!(ip_frag_key))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_frag_key>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_frag_key))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_key)).src_dst as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_key),
+ "::",
+ stringify!(src_dst)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_key)).id as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_key),
+ "::",
+ stringify!(id)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_key)).key_len as *const _ as usize },
+ 36usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_key),
+ "::",
+ stringify!(key_len)
+ )
+ );
}
/// @internal Fragmented packet to reassemble.
/// First two entries in the frags[] array are for the last and first fragments.
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct ip_frag_pkt {
/// < LRU list
pub lru: ip_frag_pkt__bindgen_ty_1,
@@ -115,91 +153,142 @@ pub struct ip_frag_pkt {
pub __bindgen_padding_0: [u64; 6usize],
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ip_frag_pkt__bindgen_ty_1 {
pub tqe_next: *mut ip_frag_pkt,
pub tqe_prev: *mut *mut ip_frag_pkt,
}
#[test]
fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<ip_frag_pkt__bindgen_ty_1>() , 16usize ,
- concat ! (
- "Size of: " , stringify ! ( ip_frag_pkt__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<ip_frag_pkt__bindgen_ty_1>() , 8usize ,
- concat ! (
- "Alignment of " , stringify ! ( ip_frag_pkt__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt__bindgen_ty_1 ) ) . tqe_next
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- ip_frag_pkt__bindgen_ty_1 ) , "::" , stringify ! ( tqe_next )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt__bindgen_ty_1 ) ) . tqe_prev
- as * const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! (
- ip_frag_pkt__bindgen_ty_1 ) , "::" , stringify ! ( tqe_prev )
- ));
-}
-impl Clone for ip_frag_pkt__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_pkt__bindgen_ty_1>(),
+ 16usize,
+ concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_frag_pkt__bindgen_ty_1>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt__bindgen_ty_1)).tqe_next as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt__bindgen_ty_1),
+ "::",
+ stringify!(tqe_next)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt__bindgen_ty_1)).tqe_prev as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt__bindgen_ty_1),
+ "::",
+ stringify!(tqe_prev)
+ )
+ );
}
impl Default for ip_frag_pkt__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_ip_frag_pkt() {
- assert_eq!(::std::mem::size_of::<ip_frag_pkt>() , 192usize , concat ! (
- "Size of: " , stringify ! ( ip_frag_pkt ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . lru as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( lru ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . key as * const _ as
- usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( key ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . start as * const _ as
- usize } , 56usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( start ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . total_size as * const _
- as usize } , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( total_size ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . frag_size as * const _
- as usize } , 68usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( frag_size ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . last_idx as * const _
- as usize } , 72usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( last_idx ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . frags as * const _ as
- usize } , 80usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( frags ) ));
-}
-impl Clone for ip_frag_pkt {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_pkt>(),
+ 192usize,
+ concat!("Size of: ", stringify!(ip_frag_pkt))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).lru as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(lru)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).key as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(key)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).start as *const _ as usize },
+ 56usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(start)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).total_size as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(total_size)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).frag_size as *const _ as usize },
+ 68usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(frag_size)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).last_idx as *const _ as usize },
+ 72usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(last_idx)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).frags as *const _ as usize },
+ 80usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(frags)
+ )
+ );
}
impl Default for ip_frag_pkt {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for ip_frag_pkt {
+ fn eq(&self, other: &ip_frag_pkt) -> bool {
+ self.lru == other.lru && self.key == other.key && self.start == other.start
+ && self.total_size == other.total_size && self.frag_size == other.frag_size
+ && self.last_idx == other.last_idx && self.frags == other.frags
+ }
}
/// < fragment mbuf
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_mbuf {
pub _address: u8,
}
-impl Clone for rte_mbuf {
- fn clone(&self) -> Self { *self }
-}
diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs
index be841432..ca4147f0 100644
--- a/tests/expectations/tests/layout_cmdline_token.rs
+++ b/tests/expectations/tests/layout_cmdline_token.rs
@@ -8,7 +8,7 @@
/// Stores a pointer to the ops struct, and the offset: the place to
/// write the parsed result in the destination structure.
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct cmdline_token_hdr {
pub ops: *mut cmdline_token_ops,
pub offset: ::std::os::raw::c_uint,
@@ -46,11 +46,6 @@ fn bindgen_test_layout_cmdline_token_hdr() {
)
);
}
-impl Clone for cmdline_token_hdr {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for cmdline_token_hdr {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -75,7 +70,7 @@ pub type cmdline_parse_token_hdr_t = cmdline_token_hdr;
/// get_help() fills the dstbuf with the help for the token. It returns
/// -1 on error and 0 on success.
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct cmdline_token_ops {
/// parse(token ptr, buf, res pts, buf len)
pub parse: ::std::option::Option<
@@ -162,11 +157,6 @@ fn bindgen_test_layout_cmdline_token_ops() {
)
);
}
-impl Clone for cmdline_token_ops {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for cmdline_token_ops {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -185,7 +175,7 @@ pub enum cmdline_numtype {
INT64 = 7,
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct cmdline_token_num_data {
pub type_: cmdline_numtype,
}
@@ -212,18 +202,13 @@ fn bindgen_test_layout_cmdline_token_num_data() {
)
);
}
-impl Clone for cmdline_token_num_data {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for cmdline_token_num_data {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct cmdline_token_num {
pub hdr: cmdline_token_hdr,
pub num_data: cmdline_token_num_data,
@@ -261,11 +246,6 @@ fn bindgen_test_layout_cmdline_token_num() {
)
);
}
-impl Clone for cmdline_token_num {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for cmdline_token_num {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs
index 8c2889ba..d5f1f1a5 100644
--- a/tests/expectations/tests/layout_eth_conf.rs
+++ b/tests/expectations/tests/layout_eth_conf.rs
@@ -52,7 +52,7 @@ pub enum rte_eth_rx_mq_mode {
}
/// A structure used to configure the RX features of an Ethernet port.
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, 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,
@@ -105,11 +105,6 @@ fn bindgen_test_layout_rte_eth_rxmode() {
)
);
}
-impl Clone for rte_eth_rxmode {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_eth_rxmode {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -126,13 +121,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 1u64 as u16;
+ let mask = 0x1 as u16;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_header_split(&mut self, val: u16) {
- let mask = 1u64 as u16;
+ let mask = 0x1 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -162,13 +157,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 2u64 as u16;
+ let mask = 0x2 as u16;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_ip_checksum(&mut self, val: u16) {
- let mask = 2u64 as u16;
+ let mask = 0x2 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -198,13 +193,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 4u64 as u16;
+ let mask = 0x4 as u16;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_vlan_filter(&mut self, val: u16) {
- let mask = 4u64 as u16;
+ let mask = 0x4 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -234,13 +229,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 8u64 as u16;
+ let mask = 0x8 as u16;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_vlan_strip(&mut self, val: u16) {
- let mask = 8u64 as u16;
+ let mask = 0x8 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -270,13 +265,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 16u64 as u16;
+ let mask = 0x10 as u16;
let val = (unit_field_val & mask) >> 4usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_vlan_extend(&mut self, val: u16) {
- let mask = 16u64 as u16;
+ let mask = 0x10 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -306,13 +301,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 32u64 as u16;
+ let mask = 0x20 as u16;
let val = (unit_field_val & mask) >> 5usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_jumbo_frame(&mut self, val: u16) {
- let mask = 32u64 as u16;
+ let mask = 0x20 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -342,13 +337,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = (unit_field_val & mask) >> 6usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_strip_crc(&mut self, val: u16) {
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -378,13 +373,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_enable_scatter(&mut self, val: u16) {
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -414,13 +409,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_enable_lro(&mut self, val: u16) {
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -452,15 +447,15 @@ impl rte_eth_rxmode {
enable_scatter: u16,
enable_lro: u16,
) -> u16 {
- (((((((((0 | ((header_split as u16 as u16) << 0usize) & (1u64 as u16)) |
- ((hw_ip_checksum as u16 as u16) << 1usize) & (2u64 as u16)) |
- ((hw_vlan_filter as u16 as u16) << 2usize) & (4u64 as u16)) |
- ((hw_vlan_strip as u16 as u16) << 3usize) & (8u64 as u16)) |
- ((hw_vlan_extend as u16 as u16) << 4usize) & (16u64 as u16)) |
- ((jumbo_frame as u16 as u16) << 5usize) & (32u64 as u16)) |
- ((hw_strip_crc as u16 as u16) << 6usize) & (64u64 as u16)) |
- ((enable_scatter as u16 as u16) << 7usize) & (128u64 as u16)) |
- ((enable_lro as u16 as u16) << 8usize) & (256u64 as u16))
+ (((((((((0 | ((header_split as u16 as u16) << 0usize) & (0x1 as u16))
+ | ((hw_ip_checksum as u16 as u16) << 1usize) & (0x2 as u16))
+ | ((hw_vlan_filter as u16 as u16) << 2usize) & (0x4 as u16))
+ | ((hw_vlan_strip as u16 as u16) << 3usize) & (0x8 as u16))
+ | ((hw_vlan_extend as u16 as u16) << 4usize) & (0x10 as u16))
+ | ((jumbo_frame as u16 as u16) << 5usize) & (0x20 as u16))
+ | ((hw_strip_crc as u16 as u16) << 6usize) & (0x40 as u16))
+ | ((enable_scatter as u16 as u16) << 7usize) & (0x80 as u16))
+ | ((enable_lro as u16 as u16) << 8usize) & (0x100 as u16))
}
}
#[repr(u32)]
@@ -475,7 +470,7 @@ pub enum rte_eth_tx_mq_mode {
}
/// A structure used to configure the TX features of an Ethernet port.
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_txmode {
/// < TX multi-queues mode.
pub mq_mode: rte_eth_tx_mq_mode,
@@ -516,11 +511,6 @@ fn bindgen_test_layout_rte_eth_txmode() {
)
);
}
-impl Clone for rte_eth_txmode {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_eth_txmode {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -537,13 +527,13 @@ impl rte_eth_txmode {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -573,13 +563,13 @@ impl rte_eth_txmode {
::std::mem::size_of::<u8>(),
)
};
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) {
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -609,13 +599,13 @@ impl rte_eth_txmode {
::std::mem::size_of::<u8>(),
)
};
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) {
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -641,9 +631,9 @@ impl rte_eth_txmode {
hw_vlan_reject_untagged: u8,
hw_vlan_insert_pvid: u8,
) -> u8 {
- (((0 | ((hw_vlan_reject_tagged as u8 as u8) << 0usize) & (1u64 as u8)) |
- ((hw_vlan_reject_untagged as u8 as u8) << 1usize) & (2u64 as u8)) |
- ((hw_vlan_insert_pvid as u8 as u8) << 2usize) & (4u64 as u8))
+ (((0 | ((hw_vlan_reject_tagged as u8 as u8) << 0usize) & (0x1 as u8))
+ | ((hw_vlan_reject_untagged as u8 as u8) << 1usize) & (0x2 as u8))
+ | ((hw_vlan_insert_pvid as u8 as u8) << 2usize) & (0x4 as u8))
}
}
/// A structure used to configure the Receive Side Scaling (RSS) feature
@@ -662,7 +652,7 @@ impl rte_eth_txmode {
/// 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)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_rss_conf {
/// < If not NULL, 40-byte hash key.
pub rss_key: *mut u8,
@@ -714,11 +704,6 @@ fn bindgen_test_layout_rte_eth_rss_conf() {
)
);
}
-impl Clone for rte_eth_rss_conf {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_eth_rss_conf {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -752,7 +737,7 @@ pub enum rte_eth_nb_pools {
/// A default pool may be used, if desired, to route all traffic which
/// does not match the vlan filter rules.
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct rte_eth_vmdq_dcb_conf {
/// < With DCB, 16 or 32 pools
pub nb_queue_pools: rte_eth_nb_pools,
@@ -767,7 +752,7 @@ pub struct rte_eth_vmdq_dcb_conf {
pub dcb_tc: [u8; 8usize],
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 {
/// < The vlan id of the received frame
pub vlan_id: u16,
@@ -812,11 +797,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() {
)
);
}
-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() {
assert_eq!(
@@ -890,18 +870,13 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_dcb_rx_conf {
/// < Possible DCB TCs, 4 or 8 TCs
pub nb_tcs: rte_eth_nb_tcs,
@@ -941,18 +916,13 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, 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,
@@ -992,18 +962,13 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_dcb_tx_conf {
/// < Possible DCB TCs, 4 or 8 TCs.
pub nb_tcs: rte_eth_nb_tcs,
@@ -1043,18 +1008,13 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_vmdq_tx_conf {
/// < VMDq mode, 64 pools.
pub nb_queue_pools: rte_eth_nb_pools,
@@ -1082,18 +1042,13 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct rte_eth_vmdq_rx_conf {
/// < VMDq only mode, 8 or 64 pools
pub nb_queue_pools: rte_eth_nb_pools,
@@ -1111,7 +1066,7 @@ pub struct rte_eth_vmdq_rx_conf {
pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize],
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 {
/// < The vlan id of the received frame
pub vlan_id: u16,
@@ -1156,11 +1111,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() {
)
);
}
-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() {
assert_eq!(
@@ -1244,11 +1194,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
@@ -1283,7 +1228,7 @@ pub enum rte_fdir_status_mode {
}
/// A structure used to define the input for IPV4 flow
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_ipv4_flow {
/// < IPv4 source address in big endian.
pub src_ip: u32,
@@ -1359,14 +1304,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() {
)
);
}
-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)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_ipv6_flow {
/// < IPv6 source address in big endian.
pub src_ip: [u32; 4usize],
@@ -1442,15 +1382,10 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() {
)
);
}
-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)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_fdir_masks {
/// < Bit mask for vlan_tci in big endian
pub vlan_tci_mask: u16,
@@ -1564,11 +1499,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() {
)
);
}
-impl Clone for rte_eth_fdir_masks {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(u32)]
/// Payload type
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -1583,7 +1513,7 @@ pub enum rte_eth_payload_type {
/// A structure used to select bytes extracted from the protocol layers to
/// flexible payload for filter
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_flex_payload_cfg {
/// < Payload type
pub type_: rte_eth_payload_type,
@@ -1622,11 +1552,6 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() {
)
);
}
-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 { ::std::mem::zeroed() }
@@ -1635,7 +1560,7 @@ impl Default for rte_eth_flex_payload_cfg {
/// A structure used to define FDIR masks for flexible payload
/// for each flow type
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_fdir_flex_mask {
pub flow_type: u16,
pub mask: [u8; 16usize],
@@ -1673,15 +1598,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_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)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_eth_fdir_flex_conf {
/// < The number of following payload cfg
pub nb_payloads: u16,
@@ -1743,11 +1663,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() {
)
);
}
-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 { ::std::mem::zeroed() }
@@ -1758,7 +1673,7 @@ impl Default for rte_eth_fdir_flex_conf {
///
/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_fdir_conf {
/// < Flow Director mode.
pub mode: rte_fdir_mode,
@@ -1844,11 +1759,6 @@ fn bindgen_test_layout_rte_fdir_conf() {
)
);
}
-impl Clone for rte_fdir_conf {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_fdir_conf {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -1856,7 +1766,7 @@ impl Default for rte_fdir_conf {
}
/// A structure used to enable/disable specific device interrupts.
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_intr_conf {
/// enable/disable lsc interrupt. 0 (default) - disable, 1 enable
pub lsc: u16,
@@ -1896,16 +1806,11 @@ fn bindgen_test_layout_rte_intr_conf() {
)
);
}
-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)]
+#[derive(Copy, Clone)]
pub struct rte_eth_conf {
/// < bitmap of ETH_LINK_SPEED_XXX of speeds to be
/// used. ETH_LINK_SPEED_FIXED disables link
@@ -1938,7 +1843,7 @@ pub struct rte_eth_conf {
pub intr_conf: rte_intr_conf,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct rte_eth_conf__bindgen_ty_1 {
/// < Port RSS configuration
pub rss_conf: rte_eth_rss_conf,
@@ -1999,18 +1904,13 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() {
)
);
}
-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 { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_eth_conf__bindgen_ty_2 {
pub vmdq_dcb_tx_conf: rte_eth_vmdq_dcb_tx_conf,
pub dcb_tx_conf: rte_eth_dcb_tx_conf,
@@ -2062,11 +1962,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() {
)
);
}
-impl Clone for rte_eth_conf__bindgen_ty_2 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_eth_conf__bindgen_ty_2 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -2175,11 +2070,6 @@ fn bindgen_test_layout_rte_eth_conf() {
)
);
}
-impl Clone for rte_eth_conf {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_eth_conf {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs
index 88e931b6..a35a9616 100644
--- a/tests/expectations/tests/layout_eth_conf_1_0.rs
+++ b/tests/expectations/tests/layout_eth_conf_1_0.rs
@@ -46,7 +46,7 @@ impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
true
}
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
pub const ETH_MQ_RX_RSS_FLAG: ::std::os::raw::c_uint = 1;
pub const ETH_MQ_RX_DCB_FLAG: ::std::os::raw::c_uint = 2;
pub const ETH_MQ_RX_VMDQ_FLAG: ::std::os::raw::c_uint = 4;
@@ -169,13 +169,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 1u64 as u16;
+ let mask = 0x1 as u16;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_header_split(&mut self, val: u16) {
- let mask = 1u64 as u16;
+ let mask = 0x1 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -205,13 +205,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 2u64 as u16;
+ let mask = 0x2 as u16;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_ip_checksum(&mut self, val: u16) {
- let mask = 2u64 as u16;
+ let mask = 0x2 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -241,13 +241,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 4u64 as u16;
+ let mask = 0x4 as u16;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_vlan_filter(&mut self, val: u16) {
- let mask = 4u64 as u16;
+ let mask = 0x4 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -277,13 +277,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 8u64 as u16;
+ let mask = 0x8 as u16;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_vlan_strip(&mut self, val: u16) {
- let mask = 8u64 as u16;
+ let mask = 0x8 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -313,13 +313,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 16u64 as u16;
+ let mask = 0x10 as u16;
let val = (unit_field_val & mask) >> 4usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_vlan_extend(&mut self, val: u16) {
- let mask = 16u64 as u16;
+ let mask = 0x10 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -349,13 +349,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 32u64 as u16;
+ let mask = 0x20 as u16;
let val = (unit_field_val & mask) >> 5usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_jumbo_frame(&mut self, val: u16) {
- let mask = 32u64 as u16;
+ let mask = 0x20 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -385,13 +385,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = (unit_field_val & mask) >> 6usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_hw_strip_crc(&mut self, val: u16) {
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -421,13 +421,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_enable_scatter(&mut self, val: u16) {
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -457,13 +457,13 @@ impl rte_eth_rxmode {
::std::mem::size_of::<u16>(),
)
};
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_enable_lro(&mut self, val: u16) {
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = val as u16 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -495,15 +495,15 @@ impl rte_eth_rxmode {
enable_scatter: u16,
enable_lro: u16,
) -> u16 {
- (((((((((0 | ((header_split as u16 as u16) << 0usize) & (1u64 as u16)) |
- ((hw_ip_checksum as u16 as u16) << 1usize) & (2u64 as u16)) |
- ((hw_vlan_filter as u16 as u16) << 2usize) & (4u64 as u16)) |
- ((hw_vlan_strip as u16 as u16) << 3usize) & (8u64 as u16)) |
- ((hw_vlan_extend as u16 as u16) << 4usize) & (16u64 as u16)) |
- ((jumbo_frame as u16 as u16) << 5usize) & (32u64 as u16)) |
- ((hw_strip_crc as u16 as u16) << 6usize) & (64u64 as u16)) |
- ((enable_scatter as u16 as u16) << 7usize) & (128u64 as u16)) |
- ((enable_lro as u16 as u16) << 8usize) & (256u64 as u16))
+ (((((((((0 | ((header_split as u16 as u16) << 0usize) & (0x1 as u16))
+ | ((hw_ip_checksum as u16 as u16) << 1usize) & (0x2 as u16))
+ | ((hw_vlan_filter as u16 as u16) << 2usize) & (0x4 as u16))
+ | ((hw_vlan_strip as u16 as u16) << 3usize) & (0x8 as u16))
+ | ((hw_vlan_extend as u16 as u16) << 4usize) & (0x10 as u16))
+ | ((jumbo_frame as u16 as u16) << 5usize) & (0x20 as u16))
+ | ((hw_strip_crc as u16 as u16) << 6usize) & (0x40 as u16))
+ | ((enable_scatter as u16 as u16) << 7usize) & (0x80 as u16))
+ | ((enable_lro as u16 as u16) << 8usize) & (0x100 as u16))
}
}
#[repr(u32)]
@@ -580,13 +580,13 @@ impl rte_eth_txmode {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -616,13 +616,13 @@ impl rte_eth_txmode {
::std::mem::size_of::<u8>(),
)
};
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) {
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -652,13 +652,13 @@ impl rte_eth_txmode {
::std::mem::size_of::<u8>(),
)
};
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) {
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -684,9 +684,9 @@ impl rte_eth_txmode {
hw_vlan_reject_untagged: u8,
hw_vlan_insert_pvid: u8,
) -> u8 {
- (((0 | ((hw_vlan_reject_tagged as u8 as u8) << 0usize) & (1u64 as u8)) |
- ((hw_vlan_reject_untagged as u8 as u8) << 1usize) & (2u64 as u8)) |
- ((hw_vlan_insert_pvid as u8 as u8) << 2usize) & (4u64 as u8))
+ (((0 | ((hw_vlan_reject_tagged as u8 as u8) << 0usize) & (0x1 as u8))
+ | ((hw_vlan_reject_untagged as u8 as u8) << 1usize) & (0x2 as u8))
+ | ((hw_vlan_insert_pvid as u8 as u8) << 2usize) & (0x4 as u8))
}
}
/// A structure used to configure the Receive Side Scaling (RSS) feature
diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs
index 72552bea..e848c52e 100644
--- a/tests/expectations/tests/layout_kni_mbuf.rs
+++ b/tests/expectations/tests/layout_kni_mbuf.rs
@@ -7,7 +7,7 @@
pub const RTE_CACHE_LINE_MIN_SIZE: ::std::os::raw::c_uint = 64;
pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64;
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct rte_kni_mbuf {
pub buf_addr: *mut ::std::os::raw::c_void,
pub buf_physaddr: u64,
@@ -33,82 +33,154 @@ pub struct rte_kni_mbuf {
}
#[test]
fn bindgen_test_layout_rte_kni_mbuf() {
- assert_eq!(::std::mem::size_of::<rte_kni_mbuf>() , 128usize , concat ! (
- "Size of: " , stringify ! ( rte_kni_mbuf ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . buf_addr as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( buf_addr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . buf_physaddr as *
- const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( buf_physaddr ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pad0 as * const _ as
- usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pad0 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . data_off as * const _
- as usize } , 18usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( data_off ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pad1 as * const _ as
- usize } , 20usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pad1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . nb_segs as * const _
- as usize } , 22usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( nb_segs ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pad4 as * const _ as
- usize } , 23usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pad4 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . ol_flags as * const _
- as usize } , 24usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( ol_flags ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pad2 as * const _ as
- usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pad2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pkt_len as * const _
- as usize } , 36usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pkt_len ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . data_len as * const _
- as usize } , 40usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( data_len ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pad3 as * const _ as
- usize } , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pad3 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . pool as * const _ as
- usize } , 72usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( pool ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_kni_mbuf ) ) . next as * const _ as
- usize } , 80usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" ,
- stringify ! ( next ) ));
-}
-impl Clone for rte_kni_mbuf {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<rte_kni_mbuf>(),
+ 128usize,
+ concat!("Size of: ", stringify!(rte_kni_mbuf))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).buf_addr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(buf_addr)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).buf_physaddr as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(buf_physaddr)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pad0 as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pad0)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).data_off as *const _ as usize },
+ 18usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(data_off)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pad1 as *const _ as usize },
+ 20usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pad1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).nb_segs as *const _ as usize },
+ 22usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(nb_segs)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pad4 as *const _ as usize },
+ 23usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pad4)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).ol_flags as *const _ as usize },
+ 24usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(ol_flags)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pad2 as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pad2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pkt_len as *const _ as usize },
+ 36usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pkt_len)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).data_len as *const _ as usize },
+ 40usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(data_len)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pad3 as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pad3)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).pool as *const _ as usize },
+ 72usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(pool)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_kni_mbuf)).next as *const _ as usize },
+ 80usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_kni_mbuf),
+ "::",
+ stringify!(next)
+ )
+ );
}
impl Default for rte_kni_mbuf {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs
index 0d86acda..24034d92 100644
--- a/tests/expectations/tests/layout_large_align_field.rs
+++ b/tests/expectations/tests/layout_large_align_field.rs
@@ -7,13 +7,15 @@
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
-impl <T> __IncompleteArrayField<T> {
+impl<T> __IncompleteArrayField<T> {
#[inline]
pub fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData)
}
#[inline]
- pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
#[inline]
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
::std::mem::transmute(self)
@@ -27,16 +29,18 @@ impl <T> __IncompleteArrayField<T> {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
-impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
-impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64;
pub const RTE_LIBRTE_IP_FRAG_MAX_FRAG: ::std::os::raw::c_uint = 4;
pub const IP_LAST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_LAST_FRAG_IDX;
@@ -53,7 +57,7 @@ pub enum _bindgen_ty_1 {
}
/// @internal fragmented mbuf
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct ip_frag {
/// < offset into the packet
pub ofs: u16,
@@ -64,35 +68,55 @@ pub struct ip_frag {
}
#[test]
fn bindgen_test_layout_ip_frag() {
- assert_eq!(::std::mem::size_of::<ip_frag>() , 16usize , concat ! (
- "Size of: " , stringify ! ( ip_frag ) ));
- assert_eq! (::std::mem::align_of::<ip_frag>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ip_frag ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag ) ) . ofs as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag ) , "::" ,
- stringify ! ( ofs ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag ) ) . len as * const _ as usize }
- , 2usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag ) , "::" ,
- stringify ! ( len ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag ) ) . mb as * const _ as usize }
- , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag ) , "::" ,
- stringify ! ( mb ) ));
-}
-impl Clone for ip_frag {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag>(),
+ 16usize,
+ concat!("Size of: ", stringify!(ip_frag))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_frag>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_frag))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag)).ofs as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag),
+ "::",
+ stringify!(ofs)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag)).len as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag),
+ "::",
+ stringify!(len)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag)).mb as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag),
+ "::",
+ stringify!(mb)
+ )
+ );
}
impl Default for ip_frag {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
/// @internal <src addr, dst_addr, id> to uniquely indetify fragmented datagram.
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct ip_frag_key {
/// < src address, first 8 bytes used for IPv4
pub src_dst: [u64; 4usize],
@@ -103,33 +127,51 @@ pub struct ip_frag_key {
}
#[test]
fn bindgen_test_layout_ip_frag_key() {
- assert_eq!(::std::mem::size_of::<ip_frag_key>() , 40usize , concat ! (
- "Size of: " , stringify ! ( ip_frag_key ) ));
- assert_eq! (::std::mem::align_of::<ip_frag_key>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ip_frag_key ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_key ) ) . src_dst as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" ,
- stringify ! ( src_dst ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_key ) ) . id as * const _ as
- usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" ,
- stringify ! ( id ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_key ) ) . key_len as * const _ as
- usize } , 36usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_key ) , "::" ,
- stringify ! ( key_len ) ));
-}
-impl Clone for ip_frag_key {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_key>(),
+ 40usize,
+ concat!("Size of: ", stringify!(ip_frag_key))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_frag_key>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_frag_key))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_key)).src_dst as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_key),
+ "::",
+ stringify!(src_dst)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_key)).id as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_key),
+ "::",
+ stringify!(id)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_key)).key_len as *const _ as usize },
+ 36usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_key),
+ "::",
+ stringify!(key_len)
+ )
+ );
}
/// @internal Fragmented packet to reassemble.
/// First two entries in the frags[] array are for the last and first fragments.
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct ip_frag_pkt {
/// < LRU list
pub lru: ip_frag_pkt__bindgen_ty_1,
@@ -148,117 +190,179 @@ pub struct ip_frag_pkt {
pub __bindgen_padding_0: [u64; 6usize],
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct ip_frag_pkt__bindgen_ty_1 {
pub tqe_next: *mut ip_frag_pkt,
pub tqe_prev: *mut *mut ip_frag_pkt,
}
#[test]
fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<ip_frag_pkt__bindgen_ty_1>() , 16usize ,
- concat ! (
- "Size of: " , stringify ! ( ip_frag_pkt__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<ip_frag_pkt__bindgen_ty_1>() , 8usize ,
- concat ! (
- "Alignment of " , stringify ! ( ip_frag_pkt__bindgen_ty_1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt__bindgen_ty_1 ) ) . tqe_next
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- ip_frag_pkt__bindgen_ty_1 ) , "::" , stringify ! ( tqe_next )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt__bindgen_ty_1 ) ) . tqe_prev
- as * const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! (
- ip_frag_pkt__bindgen_ty_1 ) , "::" , stringify ! ( tqe_prev )
- ));
-}
-impl Clone for ip_frag_pkt__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_pkt__bindgen_ty_1>(),
+ 16usize,
+ concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_frag_pkt__bindgen_ty_1>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt__bindgen_ty_1)).tqe_next as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt__bindgen_ty_1),
+ "::",
+ stringify!(tqe_next)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt__bindgen_ty_1)).tqe_prev as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt__bindgen_ty_1),
+ "::",
+ stringify!(tqe_prev)
+ )
+ );
}
impl Default for ip_frag_pkt__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_ip_frag_pkt() {
- assert_eq!(::std::mem::size_of::<ip_frag_pkt>() , 192usize , concat ! (
- "Size of: " , stringify ! ( ip_frag_pkt ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . lru as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( lru ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . key as * const _ as
- usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( key ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . start as * const _ as
- usize } , 56usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( start ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . total_size as * const _
- as usize } , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( total_size ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . frag_size as * const _
- as usize } , 68usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( frag_size ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . last_idx as * const _
- as usize } , 72usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( last_idx ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_pkt ) ) . frags as * const _ as
- usize } , 80usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_pkt ) , "::" ,
- stringify ! ( frags ) ));
-}
-impl Clone for ip_frag_pkt {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_pkt>(),
+ 192usize,
+ concat!("Size of: ", stringify!(ip_frag_pkt))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).lru as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(lru)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).key as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(key)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).start as *const _ as usize },
+ 56usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(start)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).total_size as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(total_size)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).frag_size as *const _ as usize },
+ 68usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(frag_size)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).last_idx as *const _ as usize },
+ 72usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(last_idx)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_pkt)).frags as *const _ as usize },
+ 80usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_pkt),
+ "::",
+ stringify!(frags)
+ )
+ );
}
impl Default for ip_frag_pkt {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct ip_pkt_list {
pub tqh_first: *mut ip_frag_pkt,
pub tqh_last: *mut *mut ip_frag_pkt,
}
#[test]
fn bindgen_test_layout_ip_pkt_list() {
- assert_eq!(::std::mem::size_of::<ip_pkt_list>() , 16usize , concat ! (
- "Size of: " , stringify ! ( ip_pkt_list ) ));
- assert_eq! (::std::mem::align_of::<ip_pkt_list>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( ip_pkt_list ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_pkt_list ) ) . tqh_first as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_pkt_list ) , "::" ,
- stringify ! ( tqh_first ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_pkt_list ) ) . tqh_last as * const _
- as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_pkt_list ) , "::" ,
- stringify ! ( tqh_last ) ));
-}
-impl Clone for ip_pkt_list {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_pkt_list>(),
+ 16usize,
+ concat!("Size of: ", stringify!(ip_pkt_list))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ip_pkt_list>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(ip_pkt_list))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_pkt_list)).tqh_first as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_pkt_list),
+ "::",
+ stringify!(tqh_first)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_pkt_list)).tqh_last as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_pkt_list),
+ "::",
+ stringify!(tqh_last)
+ )
+ );
}
impl Default for ip_pkt_list {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
/// fragmentation table statistics
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct ip_frag_tbl_stat {
/// < total # of find/insert attempts.
pub find_num: u64,
@@ -276,44 +380,76 @@ pub struct ip_frag_tbl_stat {
}
#[test]
fn bindgen_test_layout_ip_frag_tbl_stat() {
- assert_eq!(::std::mem::size_of::<ip_frag_tbl_stat>() , 64usize , concat !
- ( "Size of: " , stringify ! ( ip_frag_tbl_stat ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_tbl_stat ) ) . find_num as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) ,
- "::" , stringify ! ( find_num ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_tbl_stat ) ) . add_num as * const
- _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) ,
- "::" , stringify ! ( add_num ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_tbl_stat ) ) . del_num as * const
- _ as usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) ,
- "::" , stringify ! ( del_num ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_tbl_stat ) ) . reuse_num as *
- const _ as usize } , 24usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) ,
- "::" , stringify ! ( reuse_num ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_tbl_stat ) ) . fail_total as *
- const _ as usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) ,
- "::" , stringify ! ( fail_total ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ip_frag_tbl_stat ) ) . fail_nospace as *
- const _ as usize } , 40usize , concat ! (
- "Alignment of field: " , stringify ! ( ip_frag_tbl_stat ) ,
- "::" , stringify ! ( fail_nospace ) ));
-}
-impl Clone for ip_frag_tbl_stat {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ip_frag_tbl_stat>(),
+ 64usize,
+ concat!("Size of: ", stringify!(ip_frag_tbl_stat))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_tbl_stat)).find_num as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_tbl_stat),
+ "::",
+ stringify!(find_num)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_tbl_stat)).add_num as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_tbl_stat),
+ "::",
+ stringify!(add_num)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_tbl_stat)).del_num as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_tbl_stat),
+ "::",
+ stringify!(del_num)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_tbl_stat)).reuse_num as *const _ as usize },
+ 24usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_tbl_stat),
+ "::",
+ stringify!(reuse_num)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_tbl_stat)).fail_total as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_tbl_stat),
+ "::",
+ stringify!(fail_total)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ip_frag_tbl_stat)).fail_nospace as *const _ as usize },
+ 40usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ip_frag_tbl_stat),
+ "::",
+ stringify!(fail_nospace)
+ )
+ );
}
impl Default for ip_frag_tbl_stat {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
/// fragmentation table
#[repr(C)]
@@ -344,73 +480,130 @@ pub struct rte_ip_frag_tbl {
}
#[test]
fn bindgen_test_layout_rte_ip_frag_tbl() {
- assert_eq!(::std::mem::size_of::<rte_ip_frag_tbl>() , 128usize , concat !
- ( "Size of: " , stringify ! ( rte_ip_frag_tbl ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . max_cycles as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( max_cycles ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . entry_mask as *
- const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( entry_mask ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . max_entries as *
- const _ as usize } , 12usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( max_entries ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . use_entries as *
- const _ as usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( use_entries ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . bucket_entries as *
- const _ as usize } , 20usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( bucket_entries ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . nb_entries as *
- const _ as usize } , 24usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( nb_entries ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . nb_buckets as *
- const _ as usize } , 28usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( nb_buckets ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . last as * const _
- as usize } , 32usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( last ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . lru as * const _ as
- usize } , 40usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( lru ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . stat as * const _
- as usize } , 64usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( stat ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const rte_ip_frag_tbl ) ) . pkt as * const _ as
- usize } , 128usize , concat ! (
- "Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
- "::" , stringify ! ( pkt ) ));
+ assert_eq!(
+ ::std::mem::size_of::<rte_ip_frag_tbl>(),
+ 128usize,
+ concat!("Size of: ", stringify!(rte_ip_frag_tbl))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).max_cycles as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(max_cycles)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).entry_mask as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(entry_mask)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).max_entries as *const _ as usize },
+ 12usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(max_entries)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).use_entries as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(use_entries)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).bucket_entries as *const _ as usize },
+ 20usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(bucket_entries)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).nb_entries as *const _ as usize },
+ 24usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(nb_entries)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).nb_buckets as *const _ as usize },
+ 28usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(nb_buckets)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).last as *const _ as usize },
+ 32usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(last)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).lru as *const _ as usize },
+ 40usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(lru)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).stat as *const _ as usize },
+ 64usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(stat)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const rte_ip_frag_tbl)).pkt as *const _ as usize },
+ 128usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(rte_ip_frag_tbl),
+ "::",
+ stringify!(pkt)
+ )
+ );
}
impl Default for rte_ip_frag_tbl {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
/// < fragment mbuf
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct rte_mbuf {
pub _address: u8,
}
-impl Clone for rte_mbuf {
- fn clone(&self) -> Self { *self }
-}
diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs
index a671db6c..1db17172 100644
--- a/tests/expectations/tests/layout_mbuf.rs
+++ b/tests/expectations/tests/layout_mbuf.rs
@@ -12,7 +12,7 @@ pub type MARKER8 = [u8; 0usize];
pub type MARKER64 = [u64; 0usize];
/// The atomic counter structure.
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_atomic16_t {
/// < An internal counter value.
pub cnt: i16,
@@ -40,11 +40,6 @@ fn bindgen_test_layout_rte_atomic16_t() {
)
);
}
-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 {
@@ -99,7 +94,7 @@ pub struct rte_mbuf {
/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC
/// config option.
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_mbuf__bindgen_ty_1 {
/// < Atomically accessed refcnt
pub refcnt_atomic: rte_atomic16_t,
@@ -140,18 +135,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_1 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_1 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_mbuf__bindgen_ty_2 {
/// < L2/L3/L4 and tunnel information.
pub packet_type: u32,
@@ -159,7 +149,7 @@ pub union rte_mbuf__bindgen_ty_2 {
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
pub _bitfield_1: [u8; 4usize],
pub __bindgen_align: [u32; 0usize],
@@ -183,11 +173,6 @@ fn bindgen_test_layout_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 {
@@ -199,13 +184,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15u64 as u32;
+ let mask = 0xf as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_l2_type(&mut self, val: u32) {
- let mask = 15u64 as u32;
+ let mask = 0xf as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -235,13 +220,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 240u64 as u32;
+ let mask = 0xf0 as u32;
let val = (unit_field_val & mask) >> 4usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_l3_type(&mut self, val: u32) {
- let mask = 240u64 as u32;
+ let mask = 0xf0 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -271,13 +256,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 3840u64 as u32;
+ let mask = 0xf00 as u32;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_l4_type(&mut self, val: u32) {
- let mask = 3840u64 as u32;
+ let mask = 0xf00 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -307,13 +292,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 61440u64 as u32;
+ let mask = 0xf000 as u32;
let val = (unit_field_val & mask) >> 12usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_tun_type(&mut self, val: u32) {
- let mask = 61440u64 as u32;
+ let mask = 0xf000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -343,13 +328,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 983040u64 as u32;
+ let mask = 0xf0000 as u32;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_inner_l2_type(&mut self, val: u32) {
- let mask = 983040u64 as u32;
+ let mask = 0xf0000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -379,13 +364,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15728640u64 as u32;
+ let mask = 0xf00000 as u32;
let val = (unit_field_val & mask) >> 20usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_inner_l3_type(&mut self, val: u32) {
- let mask = 15728640u64 as u32;
+ let mask = 0xf00000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -415,13 +400,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 251658240u64 as u32;
+ let mask = 0xf000000 as u32;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_inner_l4_type(&mut self, val: u32) {
- let mask = 251658240u64 as u32;
+ let mask = 0xf000000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -451,13 +436,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
inner_l3_type: u32,
inner_l4_type: u32,
) -> u32 {
- (((((((0 | ((l2_type as u32 as u32) << 0usize) & (15u64 as u32)) |
- ((l3_type as u32 as u32) << 4usize) & (240u64 as u32)) |
- ((l4_type as u32 as u32) << 8usize) & (3840u64 as u32)) |
- ((tun_type as u32 as u32) << 12usize) & (61440u64 as u32)) |
- ((inner_l2_type as u32 as u32) << 16usize) & (983040u64 as u32)) |
- ((inner_l3_type as u32 as u32) << 20usize) & (15728640u64 as u32)) |
- ((inner_l4_type as u32 as u32) << 24usize) & (251658240u64 as u32))
+ (((((((0 | ((l2_type as u32 as u32) << 0usize) & (0xf as u32))
+ | ((l3_type as u32 as u32) << 4usize) & (0xf0 as u32))
+ | ((l4_type as u32 as u32) << 8usize) & (0xf00 as u32))
+ | ((tun_type as u32 as u32) << 12usize) & (0xf000 as u32))
+ | ((inner_l2_type as u32 as u32) << 16usize) & (0xf0000 as u32))
+ | ((inner_l3_type as u32 as u32) << 20usize) & (0xf00000 as u32))
+ | ((inner_l4_type as u32 as u32) << 24usize) & (0xf000000 as u32))
}
}
#[test]
@@ -483,18 +468,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_2 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_2 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_mbuf__bindgen_ty_3 {
/// < RSS hash result if RSS enabled
pub rss: u32,
@@ -507,20 +487,20 @@ pub union rte_mbuf__bindgen_ty_3 {
_bindgen_union_align: [u32; 2usize],
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
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(Copy)]
+#[derive(Copy, Clone)]
pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 {
pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1,
pub lo: u32,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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,
@@ -545,8 +525,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg
);
assert_eq!(
unsafe {
- &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))
- .hash as *const _ as usize
+ &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)).hash
+ as *const _ as usize
},
0usize,
concat!(
@@ -558,8 +538,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg
);
assert_eq!(
unsafe {
- &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)).id as
- *const _ as usize
+ &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)).id
+ as *const _ as usize
},
2usize,
concat!(
@@ -570,11 +550,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg
)
);
}
-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() {
assert_eq!(
@@ -595,8 +570,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
- &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)).lo as *const _ as
- usize
+ &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)).lo as *const _
+ as usize
},
0usize,
concat!(
@@ -607,11 +582,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -646,18 +616,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 {
pub lo: u32,
pub hi: u32,
@@ -701,11 +666,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() {
)
);
}
-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() {
assert_eq!(
@@ -759,18 +719,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_3 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_3 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_mbuf__bindgen_ty_4 {
/// < Can be used for external metadata
pub userdata: *mut ::std::os::raw::c_void,
@@ -811,18 +766,13 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_4 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_4 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union rte_mbuf__bindgen_ty_5 {
/// < combined for easy fetch
pub tx_offload: u64,
@@ -830,7 +780,7 @@ pub union rte_mbuf__bindgen_ty_5 {
_bindgen_union_align: u64,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
pub _bitfield_1: [u16; 4usize],
pub __bindgen_align: [u64; 0usize],
@@ -854,11 +804,6 @@ fn bindgen_test_layout_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 {
@@ -870,13 +815,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 127u64 as u64;
+ let mask = 0x7f as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_l2_len(&mut self, val: u64) {
- let mask = 127u64 as u64;
+ let mask = 0x7f as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -906,13 +851,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 65408u64 as u64;
+ let mask = 0xff80 as u64;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_l3_len(&mut self, val: u64) {
- let mask = 65408u64 as u64;
+ let mask = 0xff80 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -942,13 +887,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 16711680u64 as u64;
+ let mask = 0xff0000 as u64;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_l4_len(&mut self, val: u64) {
- let mask = 16711680u64 as u64;
+ let mask = 0xff0000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -978,13 +923,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 1099494850560u64 as u64;
+ let mask = 0xffff000000 as u64;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_tso_segsz(&mut self, val: u64) {
- let mask = 1099494850560u64 as u64;
+ let mask = 0xffff000000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1014,13 +959,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 561850441793536u64 as u64;
+ let mask = 0x1ff0000000000 as u64;
let val = (unit_field_val & mask) >> 40usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_outer_l3_len(&mut self, val: u64) {
- let mask = 561850441793536u64 as u64;
+ let mask = 0x1ff0000000000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1050,13 +995,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 71494644084506624u64 as u64;
+ let mask = 0xfe000000000000 as u64;
let val = (unit_field_val & mask) >> 49usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_outer_l2_len(&mut self, val: u64) {
- let mask = 71494644084506624u64 as u64;
+ let mask = 0xfe000000000000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1085,12 +1030,12 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
outer_l3_len: u64,
outer_l2_len: u64,
) -> u64 {
- ((((((0 | ((l2_len as u64 as u64) << 0usize) & (127u64 as u64)) |
- ((l3_len as u64 as u64) << 7usize) & (65408u64 as u64)) |
- ((l4_len as u64 as u64) << 16usize) & (16711680u64 as u64)) |
- ((tso_segsz as u64 as u64) << 24usize) & (1099494850560u64 as u64)) |
- ((outer_l3_len as u64 as u64) << 40usize) & (561850441793536u64 as u64)) |
- ((outer_l2_len as u64 as u64) << 49usize) & (71494644084506624u64 as u64))
+ ((((((0 | ((l2_len as u64 as u64) << 0usize) & (0x7f as u64))
+ | ((l3_len as u64 as u64) << 7usize) & (0xff80 as u64))
+ | ((l4_len as u64 as u64) << 16usize) & (0xff0000 as u64))
+ | ((tso_segsz as u64 as u64) << 24usize) & (0xffff000000 as u64))
+ | ((outer_l3_len as u64 as u64) << 40usize) & (0x1ff0000000000 as u64))
+ | ((outer_l2_len as u64 as u64) << 49usize) & (0xfe000000000000 as u64))
}
}
#[test]
@@ -1116,11 +1061,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() {
)
);
}
-impl Clone for rte_mbuf__bindgen_ty_5 {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for rte_mbuf__bindgen_ty_5 {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -1351,12 +1291,7 @@ impl Default for rte_mbuf {
}
/// < Pool from which mbuf was allocated.
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct rte_mempool {
pub _address: u8,
}
-impl Clone for rte_mempool {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs
index fe947a3a..256c8395 100644
--- a/tests/expectations/tests/layout_mbuf_1_0.rs
+++ b/tests/expectations/tests/layout_mbuf_1_0.rs
@@ -46,7 +46,7 @@ impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
true
}
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
pub const RTE_CACHE_LINE_MIN_SIZE: ::std::os::raw::c_uint = 64;
pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64;
pub type phys_addr_t = u64;
@@ -237,13 +237,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15u64 as u32;
+ let mask = 0xf as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_l2_type(&mut self, val: u32) {
- let mask = 15u64 as u32;
+ let mask = 0xf as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -273,13 +273,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 240u64 as u32;
+ let mask = 0xf0 as u32;
let val = (unit_field_val & mask) >> 4usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_l3_type(&mut self, val: u32) {
- let mask = 240u64 as u32;
+ let mask = 0xf0 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -309,13 +309,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 3840u64 as u32;
+ let mask = 0xf00 as u32;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_l4_type(&mut self, val: u32) {
- let mask = 3840u64 as u32;
+ let mask = 0xf00 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -345,13 +345,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 61440u64 as u32;
+ let mask = 0xf000 as u32;
let val = (unit_field_val & mask) >> 12usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_tun_type(&mut self, val: u32) {
- let mask = 61440u64 as u32;
+ let mask = 0xf000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -381,13 +381,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 983040u64 as u32;
+ let mask = 0xf0000 as u32;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_inner_l2_type(&mut self, val: u32) {
- let mask = 983040u64 as u32;
+ let mask = 0xf0000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -417,13 +417,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 15728640u64 as u32;
+ let mask = 0xf00000 as u32;
let val = (unit_field_val & mask) >> 20usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_inner_l3_type(&mut self, val: u32) {
- let mask = 15728640u64 as u32;
+ let mask = 0xf00000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -453,13 +453,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 251658240u64 as u32;
+ let mask = 0xf000000 as u32;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_inner_l4_type(&mut self, val: u32) {
- let mask = 251658240u64 as u32;
+ let mask = 0xf000000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -489,13 +489,13 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 {
inner_l3_type: u32,
inner_l4_type: u32,
) -> u32 {
- (((((((0 | ((l2_type as u32 as u32) << 0usize) & (15u64 as u32)) |
- ((l3_type as u32 as u32) << 4usize) & (240u64 as u32)) |
- ((l4_type as u32 as u32) << 8usize) & (3840u64 as u32)) |
- ((tun_type as u32 as u32) << 12usize) & (61440u64 as u32)) |
- ((inner_l2_type as u32 as u32) << 16usize) & (983040u64 as u32)) |
- ((inner_l3_type as u32 as u32) << 20usize) & (15728640u64 as u32)) |
- ((inner_l4_type as u32 as u32) << 24usize) & (251658240u64 as u32))
+ (((((((0 | ((l2_type as u32 as u32) << 0usize) & (0xf as u32))
+ | ((l3_type as u32 as u32) << 4usize) & (0xf0 as u32))
+ | ((l4_type as u32 as u32) << 8usize) & (0xf00 as u32))
+ | ((tun_type as u32 as u32) << 12usize) & (0xf000 as u32))
+ | ((inner_l2_type as u32 as u32) << 16usize) & (0xf0000 as u32))
+ | ((inner_l3_type as u32 as u32) << 20usize) & (0xf00000 as u32))
+ | ((inner_l4_type as u32 as u32) << 24usize) & (0xf000000 as u32))
}
}
#[test]
@@ -579,8 +579,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg
);
assert_eq!(
unsafe {
- &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))
- .hash as *const _ as usize
+ &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)).hash
+ as *const _ as usize
},
0usize,
concat!(
@@ -592,8 +592,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg
);
assert_eq!(
unsafe {
- &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)).id as
- *const _ as usize
+ &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)).id
+ as *const _ as usize
},
2usize,
concat!(
@@ -629,8 +629,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
- &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)).lo as *const _ as
- usize
+ &(*(0 as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)).lo as *const _
+ as usize
},
0usize,
concat!(
@@ -884,13 +884,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 127u64 as u64;
+ let mask = 0x7f as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_l2_len(&mut self, val: u64) {
- let mask = 127u64 as u64;
+ let mask = 0x7f as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -920,13 +920,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 65408u64 as u64;
+ let mask = 0xff80 as u64;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_l3_len(&mut self, val: u64) {
- let mask = 65408u64 as u64;
+ let mask = 0xff80 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -956,13 +956,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 16711680u64 as u64;
+ let mask = 0xff0000 as u64;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_l4_len(&mut self, val: u64) {
- let mask = 16711680u64 as u64;
+ let mask = 0xff0000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -992,13 +992,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 1099494850560u64 as u64;
+ let mask = 0xffff000000 as u64;
let val = (unit_field_val & mask) >> 24usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_tso_segsz(&mut self, val: u64) {
- let mask = 1099494850560u64 as u64;
+ let mask = 0xffff000000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1028,13 +1028,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 561850441793536u64 as u64;
+ let mask = 0x1ff0000000000 as u64;
let val = (unit_field_val & mask) >> 40usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_outer_l3_len(&mut self, val: u64) {
- let mask = 561850441793536u64 as u64;
+ let mask = 0x1ff0000000000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1064,13 +1064,13 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
::std::mem::size_of::<u64>(),
)
};
- let mask = 71494644084506624u64 as u64;
+ let mask = 0xfe000000000000 as u64;
let val = (unit_field_val & mask) >> 49usize;
unsafe { ::std::mem::transmute(val as u64) }
}
#[inline]
pub fn set_outer_l2_len(&mut self, val: u64) {
- let mask = 71494644084506624u64 as u64;
+ let mask = 0xfe000000000000 as u64;
let val = val as u64 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -1099,12 +1099,12 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 {
outer_l3_len: u64,
outer_l2_len: u64,
) -> u64 {
- ((((((0 | ((l2_len as u64 as u64) << 0usize) & (127u64 as u64)) |
- ((l3_len as u64 as u64) << 7usize) & (65408u64 as u64)) |
- ((l4_len as u64 as u64) << 16usize) & (16711680u64 as u64)) |
- ((tso_segsz as u64 as u64) << 24usize) & (1099494850560u64 as u64)) |
- ((outer_l3_len as u64 as u64) << 40usize) & (561850441793536u64 as u64)) |
- ((outer_l2_len as u64 as u64) << 49usize) & (71494644084506624u64 as u64))
+ ((((((0 | ((l2_len as u64 as u64) << 0usize) & (0x7f as u64))
+ | ((l3_len as u64 as u64) << 7usize) & (0xff80 as u64))
+ | ((l4_len as u64 as u64) << 16usize) & (0xff0000 as u64))
+ | ((tso_segsz as u64 as u64) << 24usize) & (0xffff000000 as u64))
+ | ((outer_l3_len as u64 as u64) << 40usize) & (0x1ff0000000000 as u64))
+ | ((outer_l2_len as u64 as u64) << 49usize) & (0xfe000000000000 as u64))
}
}
#[test]
diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs
index 6e2d9af3..8db72d0f 100644
--- a/tests/expectations/tests/libclang-3.8/auto.rs
+++ b/tests/expectations/tests/libclang-3.8/auto.rs
@@ -5,12 +5,12 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN3Foo4kFooE"]
+ #[link_name = "\u{1}_ZN3Foo4kFooE"]
pub static mut Foo_kFoo: bool;
}
#[test]
@@ -26,17 +26,12 @@ fn bindgen_test_layout_Foo() {
concat!("Alignment of ", stringify!(Foo))
);
}
-impl Clone for Foo {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
extern "C" {
- #[link_name = "_Z5Test2v"]
+ #[link_name = "\u{1}_Z5Test2v"]
pub fn Test2() -> ::std::os::raw::c_uint;
}
diff --git a/tests/expectations/tests/libclang-3.8/call-conv-field.rs b/tests/expectations/tests/libclang-3.8/call-conv-field.rs
index c5769c4c..b7d51283 100644
--- a/tests/expectations/tests/libclang-3.8/call-conv-field.rs
+++ b/tests/expectations/tests/libclang-3.8/call-conv-field.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct JNINativeInterface_ {
pub GetVersion: ::std::option::Option<
unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void)
@@ -46,17 +46,12 @@ fn bindgen_test_layout_JNINativeInterface_() {
)
);
}
-impl Clone for JNINativeInterface_ {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for JNINativeInterface_ {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
extern "C" {
- #[link_name = "_bar@0"]
+ #[link_name = "\u{1}_bar@0"]
pub fn bar();
}
diff --git a/tests/expectations/tests/libclang-3.8/const_bool.rs b/tests/expectations/tests/libclang-3.8/const_bool.rs
index ad6a60d8..35636842 100644
--- a/tests/expectations/tests/libclang-3.8/const_bool.rs
+++ b/tests/expectations/tests/libclang-3.8/const_bool.rs
@@ -5,16 +5,16 @@
extern "C" {
- #[link_name = "_ZL1k"]
+ #[link_name = "\u{1}_ZL1k"]
pub static mut k: bool;
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN1A1kE"]
+ #[link_name = "\u{1}_ZN1A1kE"]
pub static mut A_k: bool;
}
#[test]
@@ -30,13 +30,8 @@ fn bindgen_test_layout_A() {
concat!("Alignment of ", stringify!(A))
);
}
-impl Clone for A {
- fn clone(&self) -> Self {
- *self
- }
-}
pub type foo = bool;
extern "C" {
- #[link_name = "_ZL2k2"]
+ #[link_name = "\u{1}_ZL2k2"]
pub static mut k2: foo;
}
diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs
index 4f9e62da..8faddfe9 100644
--- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs
+++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs
@@ -12,30 +12,30 @@ pub enum _bindgen_ty_1 { foo = 4, bar = 8, }
pub type EasyToOverflow = ::std::os::raw::c_ulonglong;
pub const k: EasyToOverflow = 2147483648;
extern "C" {
- #[link_name = "k_expr"]
+ #[link_name = "\u{1}k_expr"]
pub static mut k_expr: EasyToOverflow;
}
extern "C" {
- #[link_name = "BAZ"]
+ #[link_name = "\u{1}BAZ"]
pub static mut BAZ: ::std::os::raw::c_longlong;
}
extern "C" {
- #[link_name = "fuzz"]
+ #[link_name = "\u{1}fuzz"]
pub static mut fuzz: f64;
}
extern "C" {
- #[link_name = "BAZZ"]
+ #[link_name = "\u{1}BAZZ"]
pub static mut BAZZ: ::std::os::raw::c_char;
}
extern "C" {
- #[link_name = "WAT"]
+ #[link_name = "\u{1}WAT"]
pub static mut WAT: ::std::os::raw::c_char;
}
extern "C" {
- #[link_name = "bytestring"]
+ #[link_name = "\u{1}bytestring"]
pub static mut bytestring: *const ::std::os::raw::c_char;
}
extern "C" {
- #[link_name = "NOT_UTF8"]
+ #[link_name = "\u{1}NOT_UTF8"]
pub static mut NOT_UTF8: *const ::std::os::raw::c_char;
}
diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs
index d867e73a..797d5f45 100644
--- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs
+++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs
@@ -15,12 +15,12 @@ pub struct Derived {
pub b: bool,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Usage {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN5Usage13static_memberE"]
+ #[link_name = "\u{1}_ZN5Usage13static_memberE"]
pub static mut Usage_static_member: [u32; 2usize];
}
#[test]
@@ -37,14 +37,9 @@ fn bindgen_test_layout_Usage() {
);
}
extern "C" {
- #[link_name = "_ZN5UsageC1Ev"]
+ #[link_name = "\u{1}_ZN5UsageC1Ev"]
pub fn Usage_Usage(this: *mut Usage);
}
-impl Clone for Usage {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Usage {
#[inline]
pub unsafe fn new() -> Self {
diff --git a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs
index 590f491a..7b13bb7c 100644
--- a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs
+++ b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Rooted {
pub ptr: ::std::os::raw::c_int,
}
@@ -32,10 +32,5 @@ fn bindgen_test_layout_Rooted() {
)
);
}
-impl Clone for Rooted {
- fn clone(&self) -> Self {
- *self
- }
-}
/// <div rustbindgen replaces="MaybeWrapped"></div>
pub type MaybeWrapped<a> = a;
diff --git a/tests/expectations/tests/libclang-3.9/auto.rs b/tests/expectations/tests/libclang-3.9/auto.rs
index 4f5ee5b6..2d7dfa3a 100644
--- a/tests/expectations/tests/libclang-3.9/auto.rs
+++ b/tests/expectations/tests/libclang-3.9/auto.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
@@ -23,17 +23,12 @@ fn bindgen_test_layout_Foo() {
concat!("Alignment of ", stringify!(Foo))
);
}
-impl Clone for Foo {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
extern "C" {
- #[link_name = "_Z5Test2v"]
+ #[link_name = "\u{1}_Z5Test2v"]
pub fn Test2() -> ::std::os::raw::c_uint;
}
diff --git a/tests/expectations/tests/libclang-3.9/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs
index ea794b68..a3c6fe62 100644
--- a/tests/expectations/tests/libclang-3.9/call-conv-field.rs
+++ b/tests/expectations/tests/libclang-3.9/call-conv-field.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct JNINativeInterface_ {
pub GetVersion: ::std::option::Option<
unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void)
@@ -46,17 +46,12 @@ fn bindgen_test_layout_JNINativeInterface_() {
)
);
}
-impl Clone for JNINativeInterface_ {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for JNINativeInterface_ {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
extern "stdcall" {
- #[link_name = "_bar@0"]
+ #[link_name = "\u{1}_bar@0"]
pub fn bar();
}
diff --git a/tests/expectations/tests/libclang-3.9/const_bool.rs b/tests/expectations/tests/libclang-3.9/const_bool.rs
index 7106e0ab..14f51394 100644
--- a/tests/expectations/tests/libclang-3.9/const_bool.rs
+++ b/tests/expectations/tests/libclang-3.9/const_bool.rs
@@ -6,7 +6,7 @@
pub const k: bool = true;
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub _address: u8,
}
@@ -24,10 +24,5 @@ fn bindgen_test_layout_A() {
concat!("Alignment of ", stringify!(A))
);
}
-impl Clone for A {
- fn clone(&self) -> Self {
- *self
- }
-}
pub type foo = bool;
pub const k2: foo = true;
diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs
index 84319c75..97d2eabe 100644
--- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs
+++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs
@@ -15,12 +15,12 @@ pub struct Derived {
pub b: bool,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Usage {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN5Usage13static_memberE"]
+ #[link_name = "\u{1}_ZN5Usage13static_memberE"]
pub static mut Usage_static_member: [u32; 2usize];
}
#[test]
@@ -36,8 +36,3 @@ fn bindgen_test_layout_Usage() {
concat!("Alignment of ", stringify!(Usage))
);
}
-impl Clone for Usage {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs
index 590f491a..7b13bb7c 100644
--- a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs
+++ b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Rooted {
pub ptr: ::std::os::raw::c_int,
}
@@ -32,10 +32,5 @@ fn bindgen_test_layout_Rooted() {
)
);
}
-impl Clone for Rooted {
- fn clone(&self) -> Self {
- *self
- }
-}
/// <div rustbindgen replaces="MaybeWrapped"></div>
pub type MaybeWrapped<a> = a;
diff --git a/tests/expectations/tests/libclang-4/auto.rs b/tests/expectations/tests/libclang-4/auto.rs
index 70743067..2d7dfa3a 100644
--- a/tests/expectations/tests/libclang-4/auto.rs
+++ b/tests/expectations/tests/libclang-4/auto.rs
@@ -5,20 +5,23 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
pub const Foo_kFoo: bool = true;
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
@@ -26,6 +29,6 @@ pub struct Bar {
pub _address: u8,
}
extern "C" {
- #[link_name = "_Z5Test2v"]
+ #[link_name = "\u{1}_Z5Test2v"]
pub fn Test2() -> ::std::os::raw::c_uint;
}
diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs
index 39943119..a3c6fe62 100644
--- a/tests/expectations/tests/libclang-4/call-conv-field.rs
+++ b/tests/expectations/tests/libclang-4/call-conv-field.rs
@@ -5,38 +5,53 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct JNINativeInterface_ {
- pub GetVersion: ::std::option::Option<unsafe extern "stdcall" fn(env:
- *mut ::std::os::raw::c_void)
- -> ::std::os::raw::c_int>,
+ pub GetVersion: ::std::option::Option<
+ unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void)
+ -> ::std::os::raw::c_int,
+ >,
pub __hack: ::std::os::raw::c_ulonglong,
}
#[test]
fn bindgen_test_layout_JNINativeInterface_() {
- assert_eq!(::std::mem::size_of::<JNINativeInterface_>() , 16usize , concat
- ! ( "Size of: " , stringify ! ( JNINativeInterface_ ) ));
- assert_eq! (::std::mem::align_of::<JNINativeInterface_>() , 8usize ,
- concat ! (
- "Alignment of " , stringify ! ( JNINativeInterface_ ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const JNINativeInterface_ ) ) . GetVersion as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( JNINativeInterface_ ) ,
- "::" , stringify ! ( GetVersion ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const JNINativeInterface_ ) ) . __hack as *
- const _ as usize } , 8usize , concat ! (
- "Alignment of field: " , stringify ! ( JNINativeInterface_ ) ,
- "::" , stringify ! ( __hack ) ));
-}
-impl Clone for JNINativeInterface_ {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<JNINativeInterface_>(),
+ 16usize,
+ concat!("Size of: ", stringify!(JNINativeInterface_))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<JNINativeInterface_>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(JNINativeInterface_))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const JNINativeInterface_)).GetVersion as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(JNINativeInterface_),
+ "::",
+ stringify!(GetVersion)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const JNINativeInterface_)).__hack as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(JNINativeInterface_),
+ "::",
+ stringify!(__hack)
+ )
+ );
}
impl Default for JNINativeInterface_ {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "stdcall" {
- #[link_name = "_bar@0"]
+ #[link_name = "\u{1}_bar@0"]
pub fn bar();
}
diff --git a/tests/expectations/tests/libclang-4/const_bool.rs b/tests/expectations/tests/libclang-4/const_bool.rs
index fd0273aa..14f51394 100644
--- a/tests/expectations/tests/libclang-4/const_bool.rs
+++ b/tests/expectations/tests/libclang-4/const_bool.rs
@@ -6,20 +6,23 @@
pub const k: bool = true;
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub _address: u8,
}
pub const A_k: bool = false;
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
-}
-impl Clone for A {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 1usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(A))
+ );
}
pub type foo = bool;
pub const k2: foo = true;
diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs
index 4f6794e9..97d2eabe 100644
--- a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs
+++ b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs
@@ -15,21 +15,24 @@ pub struct Derived {
pub b: bool,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Usage {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN5Usage13static_memberE"]
+ #[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::<Usage>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Usage ) ));
- assert_eq! (::std::mem::align_of::<Usage>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Usage ) ));
-}
-impl Clone for Usage {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Usage>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Usage))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Usage>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Usage))
+ );
}
diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs
index b8d4fbec..e0b8616d 100644
--- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs
+++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Rooted {
pub ptr: MaybeWrapped<::std::os::raw::c_int>,
}
@@ -32,11 +32,6 @@ fn bindgen_test_layout_Rooted() {
)
);
}
-impl Clone for Rooted {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for Rooted {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -51,8 +46,15 @@ fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() {
4usize,
concat!(
"Size of template specialization: ",
- stringify ! ( MaybeWrapped < :: std :: os :: raw :: c_int > )
+ stringify!(MaybeWrapped<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<MaybeWrapped<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(MaybeWrapped<::std::os::raw::c_int>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < MaybeWrapped < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( MaybeWrapped < :: std :: os :: raw :: c_int > ) ) );
}
diff --git a/tests/expectations/tests/mangling-ios.rs b/tests/expectations/tests/mangling-ios.rs
index 87df5e4a..0fddb5d7 100644
--- a/tests/expectations/tests/mangling-ios.rs
+++ b/tests/expectations/tests/mangling-ios.rs
@@ -5,5 +5,6 @@
extern "C" {
+ #[link_name = "\u{1}_foo"]
pub fn foo();
}
diff --git a/tests/expectations/tests/mangling-linux32.rs b/tests/expectations/tests/mangling-linux32.rs
index 5aa7bd55..7fe8f33a 100644
--- a/tests/expectations/tests/mangling-linux32.rs
+++ b/tests/expectations/tests/mangling-linux32.rs
@@ -8,21 +8,24 @@ extern "C" {
pub fn foo();
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN3Foo4sBarE"]
+ #[link_name = "\u{1}_ZN3Foo4sBarE"]
pub static mut Foo_sBar: bool;
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/mangling-linux64.rs b/tests/expectations/tests/mangling-linux64.rs
index 5aa7bd55..7fe8f33a 100644
--- a/tests/expectations/tests/mangling-linux64.rs
+++ b/tests/expectations/tests/mangling-linux64.rs
@@ -8,21 +8,24 @@ extern "C" {
pub fn foo();
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN3Foo4sBarE"]
+ #[link_name = "\u{1}_ZN3Foo4sBarE"]
pub static mut Foo_sBar: bool;
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs
index 5aa7bd55..7835dd92 100644
--- a/tests/expectations/tests/mangling-macos.rs
+++ b/tests/expectations/tests/mangling-macos.rs
@@ -5,24 +5,28 @@
extern "C" {
+ #[link_name = "\u{1}_foo"]
pub fn foo();
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN3Foo4sBarE"]
+ #[link_name = "\u{1}__ZN3Foo4sBarE"]
pub static mut Foo_sBar: bool;
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/mangling-win32.rs b/tests/expectations/tests/mangling-win32.rs
index 747ccbf5..2d2d7fcd 100644
--- a/tests/expectations/tests/mangling-win32.rs
+++ b/tests/expectations/tests/mangling-win32.rs
@@ -5,10 +5,11 @@
extern "C" {
+ #[link_name = "\u{1}_foo"]
pub fn foo();
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
@@ -29,8 +30,3 @@ fn bindgen_test_layout_Foo() {
concat!("Alignment of ", stringify!(Foo))
);
}
-impl Clone for Foo {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/mangling-win64.rs b/tests/expectations/tests/mangling-win64.rs
index ae5cc9cc..0d9c49fa 100644
--- a/tests/expectations/tests/mangling-win64.rs
+++ b/tests/expectations/tests/mangling-win64.rs
@@ -8,21 +8,24 @@ extern "C" {
pub fn foo();
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
extern "C" {
- #[link_name = "?sBar@Foo@@2_NA"]
+ #[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::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
diff --git a/tests/expectations/tests/method-mangling.rs b/tests/expectations/tests/method-mangling.rs
index 765ca5fb..f2eb6f98 100644
--- a/tests/expectations/tests/method-mangling.rs
+++ b/tests/expectations/tests/method-mangling.rs
@@ -5,25 +5,30 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
extern "C" {
- #[link_name = "_ZN3Foo4typeEv"]
+ #[link_name = "\u{1}_ZN3Foo4typeEv"]
pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_int;
}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
-}
impl Foo {
#[inline]
- pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int { Foo_type(self) }
+ pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int {
+ Foo_type(self)
+ }
}
diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-whitelisted.rs
index ad2c92fc..3f2d304e 100644
--- a/tests/expectations/tests/module-whitelisted.rs
+++ b/tests/expectations/tests/module-whitelisted.rs
@@ -9,18 +9,21 @@ pub mod root {
#[allow(unused_imports)]
use self::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Test {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Test() {
- assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Test ) ));
- assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Test ) ));
- }
- impl Clone for Test {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Test))
+ );
}
}
diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs
index 589f8995..dfa37824 100644
--- a/tests/expectations/tests/msvc-no-usr.rs
+++ b/tests/expectations/tests/msvc-no-usr.rs
@@ -5,22 +5,25 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub foo: usize,
}
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 8usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A ) ) . foo as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A ) , "::" , stringify
- ! ( foo ) ));
-}
-impl Clone for A {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 8usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(A))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A)).foo as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(A), "::", stringify!(foo))
+ );
}
diff --git a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs
index 06f1df50..86147bdd 100644
--- a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs
+++ b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs
@@ -5,47 +5,56 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Baz {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Baz() {
- assert_eq!(::std::mem::size_of::<Baz>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Baz ) ));
- assert_eq! (::std::mem::align_of::<Baz>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Baz ) ));
-}
-impl Clone for Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Baz))
+ );
}
diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs
index 9c986137..7e841f7b 100644
--- a/tests/expectations/tests/mutable.rs
+++ b/tests/expectations/tests/mutable.rs
@@ -5,30 +5,43 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
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() {
- assert_eq!(::std::mem::size_of::<C>() , 8usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . m_member as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( m_member ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . m_other as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( m_other ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 8usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).m_member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(m_member)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).m_other as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(C),
+ "::",
+ stringify!(m_other)
+ )
+ );
}
#[repr(C)]
#[derive(Debug, Default)]
@@ -37,15 +50,26 @@ pub struct NonCopiable {
}
#[test]
fn bindgen_test_layout_NonCopiable() {
- assert_eq!(::std::mem::size_of::<NonCopiable>() , 4usize , concat ! (
- "Size of: " , stringify ! ( NonCopiable ) ));
- assert_eq! (::std::mem::align_of::<NonCopiable>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( NonCopiable ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const NonCopiable ) ) . m_member as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( NonCopiable ) , "::" ,
- stringify ! ( m_member ) ));
+ assert_eq!(
+ ::std::mem::size_of::<NonCopiable>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NonCopiable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NonCopiable>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NonCopiable))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const NonCopiable)).m_member as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(NonCopiable),
+ "::",
+ stringify!(m_member)
+ )
+ );
}
#[repr(C)]
#[derive(Debug, Default)]
@@ -54,18 +78,32 @@ pub struct NonCopiableWithNonCopiableMutableMember {
}
#[test]
fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() {
- assert_eq!(::std::mem::size_of::<NonCopiableWithNonCopiableMutableMember>()
- , 4usize , concat ! (
- "Size of: " , stringify ! (
- NonCopiableWithNonCopiableMutableMember ) ));
- assert_eq! (::std::mem::align_of::<NonCopiableWithNonCopiableMutableMember>()
- , 4usize , concat ! (
- "Alignment of " , stringify ! (
- NonCopiableWithNonCopiableMutableMember ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const NonCopiableWithNonCopiableMutableMember )
- ) . m_member as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- NonCopiableWithNonCopiableMutableMember ) , "::" , stringify !
- ( m_member ) ));
+ assert_eq!(
+ ::std::mem::size_of::<NonCopiableWithNonCopiableMutableMember>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(NonCopiableWithNonCopiableMutableMember)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NonCopiableWithNonCopiableMutableMember>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(NonCopiableWithNonCopiableMutableMember)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const NonCopiableWithNonCopiableMutableMember)).m_member as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(NonCopiableWithNonCopiableMutableMember),
+ "::",
+ stringify!(m_member)
+ )
+ );
}
diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs
index dec8fabb..13a9df0e 100644
--- a/tests/expectations/tests/namespace.rs
+++ b/tests/expectations/tests/namespace.rs
@@ -9,7 +9,7 @@ pub mod root {
#[allow(unused_imports)]
use self::super::root;
extern "C" {
- #[link_name = "_Z9top_levelv"]
+ #[link_name = "\u{1}_Z9top_levelv"]
pub fn top_level();
}
pub mod whatever {
@@ -17,7 +17,7 @@ pub mod root {
use self::super::super::root;
pub type whatever_int_t = ::std::os::raw::c_int;
extern "C" {
- #[link_name = "_ZN8whatever11in_whateverEv"]
+ #[link_name = "\u{1}_ZN8whatever11in_whateverEv"]
pub fn in_whatever();
}
}
@@ -25,11 +25,11 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
extern "C" {
- #[link_name = "_ZN12_GLOBAL__N_13fooEv"]
+ #[link_name = "\u{1}_ZN12_GLOBAL__N_13fooEv"]
pub fn foo();
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub b: root::whatever::whatever_int_t,
}
@@ -52,16 +52,11 @@ pub mod root {
);
}
extern "C" {
- #[link_name = "_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"]
+ #[link_name = "\u{1}_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"]
pub fn A_lets_hope_this_works(
this: *mut root::_bindgen_mod_id_13::A,
) -> ::std::os::raw::c_int;
}
- impl Clone for A {
- fn clone(&self) -> Self {
- *self
- }
- }
impl A {
#[inline]
pub unsafe fn lets_hope_this_works(&mut self) -> ::std::os::raw::c_int {
@@ -99,15 +94,15 @@ pub mod root {
}
}
extern "C" {
- #[link_name = "_ZN1w3hehEv"]
+ #[link_name = "\u{1}_ZN1w3hehEv"]
pub fn heh() -> root::w::whatever_int_t;
}
extern "C" {
- #[link_name = "_ZN1w3fooEv"]
+ #[link_name = "\u{1}_ZN1w3fooEv"]
pub fn foo() -> root::C<::std::os::raw::c_int>;
}
extern "C" {
- #[link_name = "_ZN1w4barrEv"]
+ #[link_name = "\u{1}_ZN1w4barrEv"]
pub fn barr() -> root::C<f32>;
}
}
diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs
index 929732f6..336723bb 100644
--- a/tests/expectations/tests/nested.rs
+++ b/tests/expectations/tests/nested.rs
@@ -5,79 +5,105 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Calc {
pub w: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Calc() {
- assert_eq!(::std::mem::size_of::<Calc>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Calc ) ));
- assert_eq! (::std::mem::align_of::<Calc>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Calc ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Calc ) ) . w as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Calc ) , "::" ,
- stringify ! ( w ) ));
-}
-impl Clone for Calc {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Calc>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Calc))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Calc>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Calc))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Calc)).w as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Calc),
+ "::",
+ stringify!(w)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Test {
pub _address: u8,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Test_Size {
pub mWidth: Test_Size_Dimension,
pub mHeight: Test_Size_Dimension,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Test_Size_Dimension {
pub _base: Calc,
}
#[test]
fn bindgen_test_layout_Test_Size_Dimension() {
- assert_eq!(::std::mem::size_of::<Test_Size_Dimension>() , 4usize , concat
- ! ( "Size of: " , stringify ! ( Test_Size_Dimension ) ));
- assert_eq! (::std::mem::align_of::<Test_Size_Dimension>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( Test_Size_Dimension ) ));
-}
-impl Clone for Test_Size_Dimension {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test_Size_Dimension>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Test_Size_Dimension))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test_Size_Dimension>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Test_Size_Dimension))
+ );
}
#[test]
fn bindgen_test_layout_Test_Size() {
- assert_eq!(::std::mem::size_of::<Test_Size>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Test_Size ) ));
- assert_eq! (::std::mem::align_of::<Test_Size>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Test_Size ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test_Size ) ) . mWidth as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Test_Size ) , "::" ,
- stringify ! ( mWidth ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test_Size ) ) . mHeight as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( Test_Size ) , "::" ,
- stringify ! ( mHeight ) ));
-}
-impl Clone for Test_Size {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test_Size>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Test_Size))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test_Size>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Test_Size))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test_Size)).mWidth as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test_Size),
+ "::",
+ stringify!(mWidth)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test_Size)).mHeight as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test_Size),
+ "::",
+ stringify!(mHeight)
+ )
+ );
}
#[test]
fn bindgen_test_layout_Test() {
- assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Test ) ));
- assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Test ) ));
-}
-impl Clone for Test {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Test))
+ );
}
diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs
index 470fee41..40826106 100644
--- a/tests/expectations/tests/nested_vtable.rs
+++ b/tests/expectations/tests/nested_vtable.rs
@@ -7,61 +7,75 @@
#[repr(C)]
pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct nsISupports {
pub vtable_: *const nsISupports__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_nsISupports() {
- assert_eq!(::std::mem::size_of::<nsISupports>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsISupports ) ));
- assert_eq! (::std::mem::align_of::<nsISupports>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsISupports ) ));
-}
-impl Clone for nsISupports {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<nsISupports>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsISupports))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsISupports>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsISupports))
+ );
}
impl Default for nsISupports {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_ZN11nsISupports14QueryInterfaceEv"]
- pub fn nsISupports_QueryInterface(this: *mut ::std::os::raw::c_void)
- -> *mut nsISupports;
+ #[link_name = "\u{1}_ZN11nsISupports14QueryInterfaceEv"]
+ pub fn nsISupports_QueryInterface(this: *mut ::std::os::raw::c_void) -> *mut nsISupports;
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct nsIRunnable {
pub _base: nsISupports,
}
#[test]
fn bindgen_test_layout_nsIRunnable() {
- assert_eq!(::std::mem::size_of::<nsIRunnable>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsIRunnable ) ));
- assert_eq! (::std::mem::align_of::<nsIRunnable>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsIRunnable ) ));
-}
-impl Clone for nsIRunnable {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<nsIRunnable>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsIRunnable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsIRunnable>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsIRunnable))
+ );
}
impl Default for nsIRunnable {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Runnable {
pub _base: nsIRunnable,
}
#[test]
fn bindgen_test_layout_Runnable() {
- assert_eq!(::std::mem::size_of::<Runnable>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Runnable ) ));
- assert_eq! (::std::mem::align_of::<Runnable>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Runnable ) ));
-}
-impl Clone for Runnable {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Runnable>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Runnable))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Runnable>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Runnable))
+ );
}
impl Default for Runnable {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs
index 8021b831..0a494ba2 100644
--- a/tests/expectations/tests/nested_within_namespace.rs
+++ b/tests/expectations/tests/nested_within_namespace.rs
@@ -12,64 +12,88 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub foo: ::std::os::raw::c_int,
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bar_Baz {
pub foo: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Bar_Baz() {
- assert_eq!(::std::mem::size_of::<Bar_Baz>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Bar_Baz ) ));
- assert_eq! (::std::mem::align_of::<Bar_Baz>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( Bar_Baz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar_Baz ) ) . foo as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar_Baz ) ,
- "::" , stringify ! ( foo ) ));
- }
- impl Clone for Bar_Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar_Baz>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Bar_Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar_Baz>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar_Baz))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar_Baz)).foo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar_Baz),
+ "::",
+ stringify!(foo)
+ )
+ );
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . foo as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( foo ) ));
- }
- impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).foo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(foo)
+ )
+ );
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Baz {
pub baz: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Baz() {
- assert_eq!(::std::mem::size_of::<Baz>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Baz ) ));
- assert_eq! (::std::mem::align_of::<Baz>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Baz ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Baz ) ) . baz as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Baz ) , "::" ,
- stringify ! ( baz ) ));
- }
- impl Clone for Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Baz))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Baz)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Baz),
+ "::",
+ stringify!(baz)
+ )
+ );
}
}
}
diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs
index e67b156b..0260e548 100644
--- a/tests/expectations/tests/no-comments.rs
+++ b/tests/expectations/tests/no-comments.rs
@@ -5,22 +5,25 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub s: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . s as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( s ) ));
-}
-impl Clone for Foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).s as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(Foo), "::", stringify!(s))
+ );
}
diff --git a/tests/expectations/tests/no-hash-opaque.rs b/tests/expectations/tests/no-hash-opaque.rs
new file mode 100644
index 00000000..c4211c71
--- /dev/null
+++ b/tests/expectations/tests/no-hash-opaque.rs
@@ -0,0 +1,24 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct NoHash {
+ pub _bindgen_opaque_blob: u32,
+}
+#[test]
+fn bindgen_test_layout_NoHash() {
+ assert_eq!(
+ ::std::mem::size_of::<NoHash>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NoHash))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoHash>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NoHash))
+ );
+}
diff --git a/tests/expectations/tests/no-hash-whitelisted.rs b/tests/expectations/tests/no-hash-whitelisted.rs
new file mode 100644
index 00000000..9997d062
--- /dev/null
+++ b/tests/expectations/tests/no-hash-whitelisted.rs
@@ -0,0 +1,34 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct NoHash {
+ pub i: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_NoHash() {
+ assert_eq!(
+ ::std::mem::size_of::<NoHash>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NoHash))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoHash>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NoHash))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const NoHash)).i as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(NoHash),
+ "::",
+ stringify!(i)
+ )
+ );
+}
diff --git a/tests/expectations/tests/no-partialeq-opaque.rs b/tests/expectations/tests/no-partialeq-opaque.rs
new file mode 100644
index 00000000..1a794162
--- /dev/null
+++ b/tests/expectations/tests/no-partialeq-opaque.rs
@@ -0,0 +1,24 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct NoPartialEq {
+ pub _bindgen_opaque_blob: u32,
+}
+#[test]
+fn bindgen_test_layout_NoPartialEq() {
+ assert_eq!(
+ ::std::mem::size_of::<NoPartialEq>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NoPartialEq))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoPartialEq>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NoPartialEq))
+ );
+}
diff --git a/tests/expectations/tests/no-partialeq-whitelisted.rs b/tests/expectations/tests/no-partialeq-whitelisted.rs
new file mode 100644
index 00000000..fb1437f1
--- /dev/null
+++ b/tests/expectations/tests/no-partialeq-whitelisted.rs
@@ -0,0 +1,34 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct NoPartialEq {
+ pub i: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_NoPartialEq() {
+ assert_eq!(
+ ::std::mem::size_of::<NoPartialEq>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NoPartialEq))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoPartialEq>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NoPartialEq))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const NoPartialEq)).i as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(NoPartialEq),
+ "::",
+ stringify!(i)
+ )
+ );
+}
diff --git a/tests/expectations/tests/no-recursive-whitelisting.rs b/tests/expectations/tests/no-recursive-whitelisting.rs
index 30dc9e69..3901339a 100644
--- a/tests/expectations/tests/no-recursive-whitelisting.rs
+++ b/tests/expectations/tests/no-recursive-whitelisting.rs
@@ -11,16 +11,29 @@ pub struct Foo {
}
#[test]
fn bindgen_test_layout_Foo() {
- assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Foo ) ));
- assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Foo ) ) . baz as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Foo ) , "::" ,
- stringify ! ( baz ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(baz)
+ )
+ );
}
impl Default for Foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs
index 41b3b184..2708b21c 100644
--- a/tests/expectations/tests/no-std.rs
+++ b/tests/expectations/tests/no-std.rs
@@ -2,12 +2,14 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
#![no_std]
-mod libc { pub type c_int = i32; pub enum c_void {} }
+mod libc {
+ pub type c_int = i32;
+ pub enum c_void {}
+}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct foo {
pub a: libc::c_int,
pub b: libc::c_int,
@@ -15,29 +17,39 @@ pub struct foo {
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::core::mem::size_of::<foo>() , 16usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::core::mem::align_of::<foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . b as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::core::mem::size_of::<foo>(),
+ 16usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::core::mem::align_of::<foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).b as *const _ as usize },
+ 4usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::core::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::core::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/no_copy_opaque.rs b/tests/expectations/tests/no_copy_opaque.rs
new file mode 100644
index 00000000..8de90cd4
--- /dev/null
+++ b/tests/expectations/tests/no_copy_opaque.rs
@@ -0,0 +1,24 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct NoCopy {
+ pub _bindgen_opaque_blob: u32,
+}
+#[test]
+fn bindgen_test_layout_NoCopy() {
+ assert_eq!(
+ ::std::mem::size_of::<NoCopy>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NoCopy))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoCopy>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NoCopy))
+ );
+}
diff --git a/tests/expectations/tests/no_copy_whitelisted.rs b/tests/expectations/tests/no_copy_whitelisted.rs
new file mode 100644
index 00000000..79219625
--- /dev/null
+++ b/tests/expectations/tests/no_copy_whitelisted.rs
@@ -0,0 +1,34 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct NoCopy {
+ pub i: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_NoCopy() {
+ assert_eq!(
+ ::std::mem::size_of::<NoCopy>(),
+ 4usize,
+ concat!("Size of: ", stringify!(NoCopy))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoCopy>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(NoCopy))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const NoCopy)).i as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(NoCopy),
+ "::",
+ stringify!(i)
+ )
+ );
+}
diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs
index c367d806..c20876dc 100644
--- a/tests/expectations/tests/non-type-params.rs
+++ b/tests/expectations/tests/non-type-params.rs
@@ -7,7 +7,7 @@
pub type Array16 = u8;
pub type ArrayInt4 = [u32; 4usize];
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct UsesArray {
pub array_char_16: [u8; 16usize],
pub array_bool_8: [u8; 8usize],
@@ -15,26 +15,44 @@ pub struct UsesArray {
}
#[test]
fn bindgen_test_layout_UsesArray() {
- assert_eq!(::std::mem::size_of::<UsesArray>() , 40usize , concat ! (
- "Size of: " , stringify ! ( UsesArray ) ));
- assert_eq! (::std::mem::align_of::<UsesArray>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( UsesArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UsesArray ) ) . array_char_16 as * const
- _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( UsesArray ) , "::" ,
- stringify ! ( array_char_16 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UsesArray ) ) . array_bool_8 as * const _
- as usize } , 16usize , concat ! (
- "Alignment of field: " , stringify ! ( UsesArray ) , "::" ,
- stringify ! ( array_bool_8 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UsesArray ) ) . array_int_4 as * const _
- as usize } , 24usize , concat ! (
- "Alignment of field: " , stringify ! ( UsesArray ) , "::" ,
- stringify ! ( array_int_4 ) ));
-}
-impl Clone for UsesArray {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<UsesArray>(),
+ 40usize,
+ concat!("Size of: ", stringify!(UsesArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<UsesArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(UsesArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UsesArray)).array_char_16 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UsesArray),
+ "::",
+ stringify!(array_char_16)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UsesArray)).array_bool_8 as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UsesArray),
+ "::",
+ stringify!(array_bool_8)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UsesArray)).array_int_4 as *const _ as usize },
+ 24usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UsesArray),
+ "::",
+ stringify!(array_int_4)
+ )
+ );
}
diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs
index d9287e00..0c9f1ec6 100644
--- a/tests/expectations/tests/nsStyleAutoArray.rs
+++ b/tests/expectations/tests/nsStyleAutoArray.rs
@@ -10,8 +10,10 @@ pub struct nsTArray<T> {
pub mBuff: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for nsTArray<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for nsTArray<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -25,6 +27,8 @@ pub struct nsStyleAutoArray<T> {
pub enum nsStyleAutoArray_WithSingleInitialElement {
WITH_SINGLE_INITIAL_ELEMENT = 0,
}
-impl <T> Default for nsStyleAutoArray<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for nsStyleAutoArray<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/objc_category.rs b/tests/expectations/tests/objc_category.rs
index 2f29adc9..ba37b819 100644
--- a/tests/expectations/tests/objc_category.rs
+++ b/tests/expectations/tests/objc_category.rs
@@ -2,8 +2,7 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-#![cfg(target_os="macos")]
+#![cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
@@ -13,11 +12,15 @@ pub trait Foo {
unsafe fn method(self);
}
impl Foo for id {
- unsafe fn method(self) { msg_send!(self , method) }
+ unsafe fn method(self) {
+ msg_send!(self, method)
+ }
}
pub trait Foo_BarCategory {
unsafe fn categoryMethod(self);
}
impl Foo_BarCategory for id {
- unsafe fn categoryMethod(self) { msg_send!(self , categoryMethod) }
+ unsafe fn categoryMethod(self) {
+ msg_send!(self, categoryMethod)
+ }
}
diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs
index 31473c51..b5c15a0e 100644
--- a/tests/expectations/tests/objc_class.rs
+++ b/tests/expectations/tests/objc_class.rs
@@ -2,20 +2,21 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-#![cfg(target_os="macos")]
+#![cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
extern "C" {
- #[link_name = "fooVar"]
+ #[link_name = "\u{1}fooVar"]
pub static mut fooVar: *mut id;
}
pub trait Foo {
unsafe fn method(self);
}
impl Foo for id {
- unsafe fn method(self) { msg_send!(self , method) }
+ unsafe fn method(self) {
+ msg_send!(self, method)
+ }
}
diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs
index 3803f1f8..a10a1fca 100644
--- a/tests/expectations/tests/objc_class_method.rs
+++ b/tests/expectations/tests/objc_class_method.rs
@@ -30,13 +30,13 @@ impl Foo for id {
unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) {
msg_send!(
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
- methodWithInt: foo: ::std::os::raw::c_int
+ methodWithInt: foo
)
}
unsafe fn methodWithFoo_(foo: id) {
msg_send!(
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
- methodWithFoo: foo: id
+ methodWithFoo: foo
)
}
unsafe fn methodReturningInt() -> ::std::os::raw::c_int {
@@ -56,11 +56,6 @@ impl Foo for id {
ptr: *mut ::std::os::raw::c_char,
floatvalue: f32,
) {
- msg_send!(
- objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
- methodWithArg1: intvalue: ::std::os::raw::c_int,
- andArg2: ptr: *mut ::std::os::raw::c_char,
- andArg3: floatvalue: f32
- )
+ msg_send ! ( objc :: runtime :: Class :: get ( "Foo" ) . expect ( "Couldn't find Foo" ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
}
}
diff --git a/tests/expectations/tests/objc_interface.rs b/tests/expectations/tests/objc_interface.rs
index 1108219d..e8c1278a 100644
--- a/tests/expectations/tests/objc_interface.rs
+++ b/tests/expectations/tests/objc_interface.rs
@@ -2,14 +2,13 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-#![cfg(target_os="macos")]
+#![cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
-pub trait Foo { }
-impl Foo for id { }
-pub trait protocol_bar { }
-impl protocol_bar for id { }
+pub trait Foo {}
+impl Foo for id {}
+pub trait protocol_bar {}
+impl protocol_bar for id {}
diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs
index a43b3e69..52cad57d 100644
--- a/tests/expectations/tests/objc_interface_type.rs
+++ b/tests/expectations/tests/objc_interface_type.rs
@@ -2,42 +2,51 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-#![cfg(target_os="macos")]
+#![cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
-pub trait Foo { }
-impl Foo for id { }
+pub trait Foo {}
+impl Foo for id {}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct FooStruct {
pub foo: *mut id,
}
#[test]
fn bindgen_test_layout_FooStruct() {
- assert_eq!(::std::mem::size_of::<FooStruct>() , 8usize , concat ! (
- "Size of: " , stringify ! ( FooStruct ) ));
- assert_eq! (::std::mem::align_of::<FooStruct>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( FooStruct ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const FooStruct ) ) . foo as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( FooStruct ) , "::" ,
- stringify ! ( foo ) ));
-}
-impl Clone for FooStruct {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<FooStruct>(),
+ 8usize,
+ concat!("Size of: ", stringify!(FooStruct))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<FooStruct>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(FooStruct))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const FooStruct)).foo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(FooStruct),
+ "::",
+ stringify!(foo)
+ )
+ );
}
impl Default for FooStruct {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
pub fn fooFunc(foo: id);
}
extern "C" {
- #[link_name = "kFoo"]
+ #[link_name = "\u{1}kFoo"]
pub static mut kFoo: *const id;
}
diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs
index abf55849..bd6e748a 100644
--- a/tests/expectations/tests/objc_method.rs
+++ b/tests/expectations/tests/objc_method.rs
@@ -26,10 +26,10 @@ impl Foo for id {
msg_send!(self, method)
}
unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int) {
- msg_send!(self, methodWithInt: foo: ::std::os::raw::c_int)
+ msg_send!(self, methodWithInt: foo)
}
unsafe fn methodWithFoo_(self, foo: id) {
- msg_send!(self, methodWithFoo: foo: id)
+ msg_send!(self, methodWithFoo: foo)
}
unsafe fn methodReturningInt(self) -> ::std::os::raw::c_int {
msg_send!(self, methodReturningInt)
@@ -43,11 +43,6 @@ impl Foo for id {
ptr: *mut ::std::os::raw::c_char,
floatvalue: f32,
) {
- msg_send!(
- self,
- methodWithArg1: intvalue: ::std::os::raw::c_int,
- andArg2: ptr: *mut ::std::os::raw::c_char,
- andArg3: floatvalue: f32
- )
+ msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
}
}
diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs
index 16e0b4ba..4f98f9fb 100644
--- a/tests/expectations/tests/objc_property_fnptr.rs
+++ b/tests/expectations/tests/objc_property_fnptr.rs
@@ -23,9 +23,6 @@ impl Foo for id {
self,
func: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>,
) {
- msg_send!(
- self,
- setFunc: func: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>
- )
+ msg_send!(self, setFunc: func)
}
}
diff --git a/tests/expectations/tests/objc_protocol.rs b/tests/expectations/tests/objc_protocol.rs
index aa7e7291..33a81fa4 100644
--- a/tests/expectations/tests/objc_protocol.rs
+++ b/tests/expectations/tests/objc_protocol.rs
@@ -2,14 +2,13 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-#![cfg(target_os="macos")]
+#![cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
-pub trait protocol_Foo { }
-impl protocol_Foo for id { }
-pub trait Foo { }
-impl Foo for id { }
+pub trait protocol_Foo {}
+impl protocol_Foo for id {}
+pub trait Foo {}
+impl Foo for id {}
diff --git a/tests/expectations/tests/objc_sel_and_id.rs b/tests/expectations/tests/objc_sel_and_id.rs
index 0784c21e..8802c206 100644
--- a/tests/expectations/tests/objc_sel_and_id.rs
+++ b/tests/expectations/tests/objc_sel_and_id.rs
@@ -2,19 +2,18 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-#![cfg(target_os="macos")]
+#![cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
extern "C" {
- #[link_name = "object"]
+ #[link_name = "\u{1}object"]
pub static mut object: id;
}
extern "C" {
- #[link_name = "selector"]
+ #[link_name = "\u{1}selector"]
pub static mut selector: objc::runtime::Sel;
}
extern "C" {
diff --git a/tests/expectations/tests/objc_whitelist.rs b/tests/expectations/tests/objc_whitelist.rs
index 4eba7c7f..38881ad0 100644
--- a/tests/expectations/tests/objc_whitelist.rs
+++ b/tests/expectations/tests/objc_whitelist.rs
@@ -1,8 +1,7 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types,
- non_upper_case_globals)]
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#![cfg(target_os = "macos")]
#[macro_use]
@@ -19,8 +18,7 @@ impl protocol_SomeProtocol for id {
}
unsafe fn protocolClassMethod() {
msg_send!(
- objc::runtime::Class::get("SomeProtocol")
- .expect("Couldn't find SomeProtocol"),
+ objc::runtime::Class::get("SomeProtocol").expect("Couldn't find SomeProtocol"),
protocolClassMethod
)
}
@@ -35,8 +33,7 @@ impl WhitelistMe for id {
}
unsafe fn classMethod() {
msg_send!(
- objc::runtime::Class::get("WhitelistMe")
- .expect("Couldn't find WhitelistMe"),
+ objc::runtime::Class::get("WhitelistMe").expect("Couldn't find WhitelistMe"),
classMethod
)
}
diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs
index 13fb00ba..5ac15b38 100644
--- a/tests/expectations/tests/only_bitfields.rs
+++ b/tests/expectations/tests/only_bitfields.rs
@@ -4,11 +4,10 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[repr(C, packed)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct C {
pub _bitfield_1: u8,
- pub __bindgen_align: [u8; 0usize],
}
#[test]
fn bindgen_test_layout_C() {
@@ -23,11 +22,6 @@ fn bindgen_test_layout_C() {
concat!("Alignment of ", stringify!(C))
);
}
-impl Clone for C {
- fn clone(&self) -> Self {
- *self
- }
-}
impl C {
#[inline]
pub fn a(&self) -> bool {
@@ -39,13 +33,13 @@ impl C {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_a(&mut self, val: bool) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -75,13 +69,13 @@ impl C {
::std::mem::size_of::<u8>(),
)
};
- let mask = 254u64 as u8;
+ let mask = 0xfe as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_b(&mut self, val: bool) {
- let mask = 254u64 as u8;
+ let mask = 0xfe as u8;
let val = val as u8 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -103,7 +97,7 @@ impl C {
}
#[inline]
pub fn new_bitfield_1(a: bool, b: bool) -> u8 {
- ((0 | ((a as u8 as u8) << 0usize) & (1u64 as u8)) |
- ((b as u8 as u8) << 1usize) & (254u64 as u8))
+ ((0 | ((a as u8 as u8) << 0usize) & (0x1 as u8))
+ | ((b as u8 as u8) << 1usize) & (0xfe as u8))
}
}
diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs
index 20b44d7e..3e00e0ed 100644
--- a/tests/expectations/tests/opaque-template-inst-member-2.rs
+++ b/tests/expectations/tests/opaque-template-inst-member-2.rs
@@ -9,10 +9,12 @@
/// where we are OK to derive Debug/Hash/PartialEq.
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
-pub struct OpaqueTemplate {}
+pub struct OpaqueTemplate {
+ pub _address: u8,
+}
/// Should derive Debug/Hash/PartialEq.
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ContainsOpaqueTemplate {
pub mBlah: u32,
pub mBaz: ::std::os::raw::c_int,
@@ -50,14 +52,9 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() {
)
);
}
-impl Clone for ContainsOpaqueTemplate {
- fn clone(&self) -> Self {
- *self
- }
-}
/// Should also derive Debug/Hash/PartialEq.
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct InheritsOpaqueTemplate {
pub _base: u8,
pub wow: *mut ::std::os::raw::c_char,
@@ -85,11 +82,6 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() {
)
);
}
-impl Clone for InheritsOpaqueTemplate {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for InheritsOpaqueTemplate {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs
index 0bef4c86..60c6d846 100644
--- a/tests/expectations/tests/opaque-template-inst-member.rs
+++ b/tests/expectations/tests/opaque-template-inst-member.rs
@@ -7,9 +7,10 @@
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct OpaqueTemplate {
+ pub _address: u8,
}
-/// This should not end up deriving Debug/Hash/PartialEq because its `mBlah` field cannot derive
-/// Debug/Hash/PartialEq because the instantiation's definition cannot derive Debug/Hash/PartialEq.
+/// This should not end up deriving Debug/Hash because its `mBlah` field cannot derive
+/// Debug/Hash because the instantiation's definition cannot derive Debug/Hash.
#[repr(C)]
pub struct ContainsOpaqueTemplate {
pub mBlah: [u32; 101usize],
@@ -17,27 +18,48 @@ pub struct ContainsOpaqueTemplate {
}
#[test]
fn bindgen_test_layout_ContainsOpaqueTemplate() {
- assert_eq!(::std::mem::size_of::<ContainsOpaqueTemplate>() , 408usize ,
- concat ! ( "Size of: " , stringify ! ( ContainsOpaqueTemplate )
- ));
- assert_eq! (::std::mem::align_of::<ContainsOpaqueTemplate>() , 4usize ,
- concat ! (
- "Alignment of " , stringify ! ( ContainsOpaqueTemplate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContainsOpaqueTemplate ) ) . mBlah as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ContainsOpaqueTemplate
- ) , "::" , stringify ! ( mBlah ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContainsOpaqueTemplate ) ) . mBaz as *
- const _ as usize } , 404usize , concat ! (
- "Alignment of field: " , stringify ! ( ContainsOpaqueTemplate
- ) , "::" , stringify ! ( mBaz ) ));
+ assert_eq!(
+ ::std::mem::size_of::<ContainsOpaqueTemplate>(),
+ 408usize,
+ concat!("Size of: ", stringify!(ContainsOpaqueTemplate))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ContainsOpaqueTemplate>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ContainsOpaqueTemplate))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContainsOpaqueTemplate)).mBlah as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContainsOpaqueTemplate),
+ "::",
+ stringify!(mBlah)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContainsOpaqueTemplate)).mBaz as *const _ as usize },
+ 404usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContainsOpaqueTemplate),
+ "::",
+ stringify!(mBaz)
+ )
+ );
}
impl Default for ContainsOpaqueTemplate {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-/// This shold not end up deriving Debug/Hash/PartialEq either, for similar reasons, although
+impl ::std::cmp::PartialEq for ContainsOpaqueTemplate {
+ fn eq(&self, other: &ContainsOpaqueTemplate) -> bool {
+ &self.mBlah[..] == &other.mBlah[..] && self.mBaz == other.mBaz
+ }
+}
+/// This should not end up deriving Debug/Hash either, for similar reasons, although
/// we're exercising base member edges now.
#[repr(C)]
pub struct InheritsOpaqueTemplate {
@@ -46,18 +68,34 @@ pub struct InheritsOpaqueTemplate {
}
#[test]
fn bindgen_test_layout_InheritsOpaqueTemplate() {
- assert_eq!(::std::mem::size_of::<InheritsOpaqueTemplate>() , 416usize ,
- concat ! ( "Size of: " , stringify ! ( InheritsOpaqueTemplate )
- ));
- assert_eq! (::std::mem::align_of::<InheritsOpaqueTemplate>() , 8usize ,
- concat ! (
- "Alignment of " , stringify ! ( InheritsOpaqueTemplate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const InheritsOpaqueTemplate ) ) . wow as *
- const _ as usize } , 408usize , concat ! (
- "Alignment of field: " , stringify ! ( InheritsOpaqueTemplate
- ) , "::" , stringify ! ( wow ) ));
+ assert_eq!(
+ ::std::mem::size_of::<InheritsOpaqueTemplate>(),
+ 416usize,
+ concat!("Size of: ", stringify!(InheritsOpaqueTemplate))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<InheritsOpaqueTemplate>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(InheritsOpaqueTemplate))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const InheritsOpaqueTemplate)).wow as *const _ as usize },
+ 408usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(InheritsOpaqueTemplate),
+ "::",
+ stringify!(wow)
+ )
+ );
}
impl Default for InheritsOpaqueTemplate {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for InheritsOpaqueTemplate {
+ fn eq(&self, other: &InheritsOpaqueTemplate) -> bool {
+ &self._base[..] == &other._base[..] && self.wow == other.wow
+ }
}
diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs
index 09818446..45d8a7d8 100644
--- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs
+++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs
@@ -23,7 +23,7 @@ pub mod root {
}
}
#[repr(C)]
- #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+ #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Foo {
pub c: ::std::os::raw::c_char,
}
@@ -45,13 +45,8 @@ pub mod root {
concat!("Alignment of field: ", stringify!(Foo), "::", stringify!(c))
);
}
- impl Clone for Foo {
- fn clone(&self) -> Self {
- *self
- }
- }
#[repr(C)]
- #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+ #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Bar {
pub i: ::std::os::raw::c_int,
}
@@ -73,13 +68,8 @@ pub mod root {
concat!("Alignment of field: ", stringify!(Bar), "::", stringify!(i))
);
}
- impl Clone for Bar {
- fn clone(&self) -> Self {
- *self
- }
- }
#[repr(C)]
- #[derive(Debug, Copy, Hash, PartialEq, Eq)]
+ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ContainsInstantiation {
pub not_opaque: root::zoidberg::Template<root::zoidberg::Foo>,
}
@@ -106,18 +96,13 @@ pub mod root {
)
);
}
- impl Clone for ContainsInstantiation {
- fn clone(&self) -> Self {
- *self
- }
- }
impl Default for ContainsInstantiation {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
- #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+ #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ContainsOpaqueInstantiation {
pub opaque: u32,
}
@@ -146,11 +131,6 @@ pub mod root {
)
);
}
- impl Clone for ContainsOpaqueInstantiation {
- fn clone(&self) -> Self {
- *self
- }
- }
}
#[test]
fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() {
@@ -159,9 +139,16 @@ pub mod root {
1usize,
concat!(
"Size of template specialization: ",
- stringify ! ( root :: zoidberg :: Template < root :: zoidberg :: Foo > )
+ stringify!(root::zoidberg::Template<root::zoidberg::Foo>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<root::zoidberg::Template<root::zoidberg::Foo>>(),
+ 1usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(root::zoidberg::Template<root::zoidberg::Foo>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < root :: zoidberg :: Template < root :: zoidberg :: Foo > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: zoidberg :: Template < root :: zoidberg :: Foo > ) ) );
}
}
diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs
index 480dba48..02788d76 100644
--- a/tests/expectations/tests/opaque-template-instantiation.rs
+++ b/tests/expectations/tests/opaque-template-instantiation.rs
@@ -16,7 +16,7 @@ impl<T> Default for Template<T> {
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ContainsInstantiation {
pub not_opaque: Template<::std::os::raw::c_char>,
}
@@ -43,18 +43,13 @@ fn bindgen_test_layout_ContainsInstantiation() {
)
);
}
-impl Clone for ContainsInstantiation {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for ContainsInstantiation {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ContainsOpaqueInstantiation {
pub opaque: u32,
}
@@ -81,11 +76,6 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() {
)
);
}
-impl Clone for ContainsOpaqueInstantiation {
- fn clone(&self) -> Self {
- *self
- }
-}
#[test]
fn __bindgen_test_layout_Template_open0_char_close0_instantiation() {
assert_eq!(
@@ -93,8 +83,15 @@ fn __bindgen_test_layout_Template_open0_char_close0_instantiation() {
1usize,
concat!(
"Size of template specialization: ",
- stringify ! ( Template < :: std :: os :: raw :: c_char > )
+ stringify!(Template<::std::os::raw::c_char>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Template<::std::os::raw::c_char>>(),
+ 1usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(Template<::std::os::raw::c_char>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < Template < :: std :: os :: raw :: c_char > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Template < :: std :: os :: raw :: c_char > ) ) );
}
diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs
index 9d28d7c2..87d91f3c 100644
--- a/tests/expectations/tests/opaque-tracing.rs
+++ b/tests/expectations/tests/opaque-tracing.rs
@@ -5,21 +5,24 @@
extern "C" {
- #[link_name = "_Z3fooP9Container"]
+ #[link_name = "\u{1}_Z3fooP9Container"]
pub fn foo(c: *mut Container);
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Container {
pub _bindgen_opaque_blob: [u32; 2usize],
}
#[test]
fn bindgen_test_layout_Container() {
- assert_eq!(::std::mem::size_of::<Container>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Container ) ));
- assert_eq! (::std::mem::align_of::<Container>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Container ) ));
-}
-impl Clone for Container {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Container>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Container))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Container>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Container))
+ );
}
diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs
index 49cfc5fc..92d28e4d 100644
--- a/tests/expectations/tests/opaque_in_struct.rs
+++ b/tests/expectations/tests/opaque_in_struct.rs
@@ -7,7 +7,7 @@
/// <div rustbindgen opaque>
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct opaque {
pub _bindgen_opaque_blob: u32,
}
@@ -24,13 +24,8 @@ fn bindgen_test_layout_opaque() {
concat!("Alignment of ", stringify!(opaque))
);
}
-impl Clone for opaque {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct container {
pub contained: opaque,
}
@@ -57,8 +52,3 @@ fn bindgen_test_layout_container() {
)
);
}
-impl Clone for container {
- fn clone(&self) -> Self {
- *self
- }
-}
diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs
index 6eb7b672..6543c7c2 100644
--- a/tests/expectations/tests/opaque_pointer.rs
+++ b/tests/expectations/tests/opaque_pointer.rs
@@ -7,7 +7,7 @@
/// <div rustbindgen opaque></div>
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct OtherOpaque {
pub _bindgen_opaque_blob: u32,
}
@@ -24,17 +24,14 @@ fn bindgen_test_layout_OtherOpaque() {
concat!("Alignment of ", stringify!(OtherOpaque))
);
}
-impl Clone for OtherOpaque {
- fn clone(&self) -> Self {
- *self
- }
-}
/// <div rustbindgen opaque></div>
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
-pub struct Opaque {}
+pub struct Opaque {
+ pub _address: u8,
+}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq)]
pub struct WithOpaquePtr {
pub whatever: *mut u8,
pub other: u32,
@@ -83,11 +80,6 @@ fn bindgen_test_layout_WithOpaquePtr() {
)
);
}
-impl Clone for WithOpaquePtr {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for WithOpaquePtr {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/overflowed_enum.rs b/tests/expectations/tests/overflowed_enum.rs
index bc4a5347..0e8700dc 100644
--- a/tests/expectations/tests/overflowed_enum.rs
+++ b/tests/expectations/tests/overflowed_enum.rs
@@ -13,4 +13,7 @@ pub enum Foo {
}
#[repr(u16)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum Bar { One = 1, Big = 2, }
+pub enum Bar {
+ One = 1,
+ Big = 2,
+}
diff --git a/tests/expectations/tests/overloading.rs b/tests/expectations/tests/overloading.rs
index 45c3ead1..28b783c3 100644
--- a/tests/expectations/tests/overloading.rs
+++ b/tests/expectations/tests/overloading.rs
@@ -5,19 +5,18 @@
extern "C" {
- #[link_name = "_Z8Evaluatec"]
+ #[link_name = "\u{1}_Z8Evaluatec"]
pub fn Evaluate(r: ::std::os::raw::c_char) -> bool;
}
extern "C" {
- #[link_name = "_Z8Evaluateii"]
- pub fn Evaluate1(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int)
- -> bool;
+ #[link_name = "\u{1}_Z8Evaluateii"]
+ pub fn Evaluate1(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> bool;
}
extern "C" {
- #[link_name = "_ZN3foo10MyFunctionEv"]
+ #[link_name = "\u{1}_ZN3foo10MyFunctionEv"]
pub fn foo_MyFunction();
}
extern "C" {
- #[link_name = "_ZN3bar10MyFunctionEv"]
+ #[link_name = "\u{1}_ZN3bar10MyFunctionEv"]
pub fn bar_MyFunction();
}
diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/tests/expectations/tests/prepend-enum-constified-variant.rs
index d5dca70c..df9ecf3c 100644
--- a/tests/expectations/tests/prepend-enum-constified-variant.rs
+++ b/tests/expectations/tests/prepend-enum-constified-variant.rs
@@ -7,4 +7,6 @@
pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum AVCodecID { AV_CODEC_ID_FIRST_UNKNOWN = 98304, }
+pub enum AVCodecID {
+ AV_CODEC_ID_FIRST_UNKNOWN = 98304,
+}
diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs
index e29ad1ba..400373f8 100644
--- a/tests/expectations/tests/private.rs
+++ b/tests/expectations/tests/private.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct HasPrivate {
pub mNotPrivate: ::std::os::raw::c_int,
/// <div rustbindgen private></div>
@@ -13,54 +13,80 @@ pub struct HasPrivate {
}
#[test]
fn bindgen_test_layout_HasPrivate() {
- assert_eq!(::std::mem::size_of::<HasPrivate>() , 8usize , concat ! (
- "Size of: " , stringify ! ( HasPrivate ) ));
- assert_eq! (::std::mem::align_of::<HasPrivate>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( HasPrivate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const HasPrivate ) ) . mNotPrivate as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( HasPrivate ) , "::" ,
- stringify ! ( mNotPrivate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const HasPrivate ) ) . mIsPrivate as * const _
- as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( HasPrivate ) , "::" ,
- stringify ! ( mIsPrivate ) ));
-}
-impl Clone for HasPrivate {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<HasPrivate>(),
+ 8usize,
+ concat!("Size of: ", stringify!(HasPrivate))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<HasPrivate>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(HasPrivate))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const HasPrivate)).mNotPrivate as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(HasPrivate),
+ "::",
+ stringify!(mNotPrivate)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const HasPrivate)).mIsPrivate as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(HasPrivate),
+ "::",
+ stringify!(mIsPrivate)
+ )
+ );
}
/// <div rustbindgen private></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct VeryPrivate {
mIsPrivate: ::std::os::raw::c_int,
mIsAlsoPrivate: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_VeryPrivate() {
- assert_eq!(::std::mem::size_of::<VeryPrivate>() , 8usize , concat ! (
- "Size of: " , stringify ! ( VeryPrivate ) ));
- assert_eq! (::std::mem::align_of::<VeryPrivate>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( VeryPrivate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const VeryPrivate ) ) . mIsPrivate as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( VeryPrivate ) , "::" ,
- stringify ! ( mIsPrivate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const VeryPrivate ) ) . mIsAlsoPrivate as *
- const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( VeryPrivate ) , "::" ,
- stringify ! ( mIsAlsoPrivate ) ));
-}
-impl Clone for VeryPrivate {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<VeryPrivate>(),
+ 8usize,
+ concat!("Size of: ", stringify!(VeryPrivate))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<VeryPrivate>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(VeryPrivate))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const VeryPrivate)).mIsPrivate as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(VeryPrivate),
+ "::",
+ stringify!(mIsPrivate)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const VeryPrivate)).mIsAlsoPrivate as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(VeryPrivate),
+ "::",
+ stringify!(mIsAlsoPrivate)
+ )
+ );
}
/// <div rustbindgen private></div>
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct ContradictPrivate {
/// <div rustbindgen private="false"></div>
pub mNotPrivate: ::std::os::raw::c_int,
@@ -68,21 +94,34 @@ pub struct ContradictPrivate {
}
#[test]
fn bindgen_test_layout_ContradictPrivate() {
- assert_eq!(::std::mem::size_of::<ContradictPrivate>() , 8usize , concat !
- ( "Size of: " , stringify ! ( ContradictPrivate ) ));
- assert_eq! (::std::mem::align_of::<ContradictPrivate>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( ContradictPrivate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContradictPrivate ) ) . mNotPrivate as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( ContradictPrivate ) ,
- "::" , stringify ! ( mNotPrivate ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const ContradictPrivate ) ) . mIsPrivate as *
- const _ as usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( ContradictPrivate ) ,
- "::" , stringify ! ( mIsPrivate ) ));
-}
-impl Clone for ContradictPrivate {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<ContradictPrivate>(),
+ 8usize,
+ concat!("Size of: ", stringify!(ContradictPrivate))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ContradictPrivate>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(ContradictPrivate))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContradictPrivate)).mNotPrivate as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContradictPrivate),
+ "::",
+ stringify!(mNotPrivate)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContradictPrivate)).mIsPrivate as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContradictPrivate),
+ "::",
+ stringify!(mIsPrivate)
+ )
+ );
}
diff --git a/tests/expectations/tests/public-dtor.rs b/tests/expectations/tests/public-dtor.rs
index bf8f1e58..f551c2cb 100644
--- a/tests/expectations/tests/public-dtor.rs
+++ b/tests/expectations/tests/public-dtor.rs
@@ -11,16 +11,24 @@ pub struct cv_String {
}
#[test]
fn bindgen_test_layout_cv_String() {
- assert_eq!(::std::mem::size_of::<cv_String>() , 1usize , concat ! (
- "Size of: " , stringify ! ( cv_String ) ));
- assert_eq! (::std::mem::align_of::<cv_String>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( cv_String ) ));
+ assert_eq!(
+ ::std::mem::size_of::<cv_String>(),
+ 1usize,
+ concat!("Size of: ", stringify!(cv_String))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<cv_String>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(cv_String))
+ );
}
extern "C" {
- #[link_name = "_ZN2cv6StringD1Ev"]
+ #[link_name = "\u{1}_ZN2cv6StringD1Ev"]
pub fn cv_String_String_destructor(this: *mut cv_String);
}
impl cv_String {
#[inline]
- pub unsafe fn destruct(&mut self) { cv_String_String_destructor(self) }
+ pub unsafe fn destruct(&mut self) {
+ cv_String_String_destructor(self)
+ }
}
diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs
index dc1465c3..14675a67 100644
--- a/tests/expectations/tests/ref_argument_array.rs
+++ b/tests/expectations/tests/ref_argument_array.rs
@@ -8,26 +8,32 @@ pub const NSID_LENGTH: ::std::os::raw::c_uint = 10;
#[repr(C)]
pub struct nsID__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct nsID {
pub vtable_: *const nsID__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_nsID() {
- assert_eq!(::std::mem::size_of::<nsID>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsID ) ));
- assert_eq! (::std::mem::align_of::<nsID>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsID ) ));
-}
-impl Clone for nsID {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<nsID>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsID))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsID>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsID))
+ );
}
impl Default for nsID {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_ZN4nsID16ToProvidedStringERA10_c"]
- pub fn nsID_ToProvidedString(this: *mut ::std::os::raw::c_void,
- aDest:
- *mut [::std::os::raw::c_char; 10usize]);
+ #[link_name = "\u{1}_ZN4nsID16ToProvidedStringERA10_c"]
+ pub fn nsID_ToProvidedString(
+ this: *mut ::std::os::raw::c_void,
+ aDest: *mut [::std::os::raw::c_char; 10usize],
+ );
}
diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs
index c9e85911..57a11871 100644
--- a/tests/expectations/tests/reparented_replacement.rs
+++ b/tests/expectations/tests/reparented_replacement.rs
@@ -13,24 +13,32 @@ pub mod root {
use self::super::super::root;
/// <div rustbindgen replaces="foo::Bar"></div>
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub bazz: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . bazz as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( bazz ) ));
- }
- impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).bazz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(bazz)
+ )
+ );
}
}
pub type ReferencesBar = root::foo::Bar;
diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs
index 49185e32..5f85dc32 100644
--- a/tests/expectations/tests/replace_use.rs
+++ b/tests/expectations/tests/replace_use.rs
@@ -12,7 +12,7 @@ pub struct nsTArray {
pub y: ::std::os::raw::c_uint,
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Test {
pub a: nsTArray,
}
@@ -39,11 +39,6 @@ fn bindgen_test_layout_Test() {
)
);
}
-impl Clone for Test {
- fn clone(&self) -> Self {
- *self
- }
-}
#[test]
fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() {
assert_eq!(
diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs
index 7f8127fd..9d49052e 100644
--- a/tests/expectations/tests/replaces_double.rs
+++ b/tests/expectations/tests/replaces_double.rs
@@ -10,8 +10,10 @@ pub struct Wrapper_Wrapped<T> {
pub t: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Wrapper_Wrapped<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Wrapper_Wrapped<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub type Wrapper_Type<T> = Wrapper_Wrapped<T>;
#[repr(C)]
@@ -22,6 +24,8 @@ pub struct Rooted<T> {
}
/// <div rustbindgen replaces="Rooted_MaybeWrapped"></div>
pub type Rooted_MaybeWrapped<T> = T;
-impl <T> Default for Rooted<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Rooted<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs
index e406cf33..b89568ec 100644
--- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs
+++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs
@@ -10,28 +10,41 @@ pub struct JS_Zone {
_unused: [u8; 0],
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
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() {
- assert_eq!(::std::mem::size_of::<JS_shadow_Zone>() , 8usize , concat ! (
- "Size of: " , stringify ! ( JS_shadow_Zone ) ));
- assert_eq! (::std::mem::align_of::<JS_shadow_Zone>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( JS_shadow_Zone ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const JS_shadow_Zone ) ) . x as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( JS_shadow_Zone ) , "::"
- , stringify ! ( x ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const JS_shadow_Zone ) ) . y as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( JS_shadow_Zone ) , "::"
- , stringify ! ( y ) ));
-}
-impl Clone for JS_shadow_Zone {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<JS_shadow_Zone>(),
+ 8usize,
+ concat!("Size of: ", stringify!(JS_shadow_Zone))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<JS_shadow_Zone>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(JS_shadow_Zone))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const JS_shadow_Zone)).x as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(JS_shadow_Zone),
+ "::",
+ stringify!(x)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const JS_shadow_Zone)).y as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(JS_shadow_Zone),
+ "::",
+ stringify!(y)
+ )
+ );
}
diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs
new file mode 100644
index 00000000..96ad8129
--- /dev/null
+++ b/tests/expectations/tests/sentry-defined-multiple-times.rs
@@ -0,0 +1,358 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
+pub mod root {
+ #[allow(unused_imports)]
+ use self::super::root;
+ pub mod whatever {
+ #[allow(unused_imports)]
+ use self::super::super::root;
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct Wrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct Wrapper_sentry {
+ pub i_am_wrapper_sentry: ::std::os::raw::c_int,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct sentry {
+ pub i_am_plain_sentry: bool,
+ }
+ #[test]
+ fn bindgen_test_layout_sentry() {
+ assert_eq!(
+ ::std::mem::size_of::<sentry>(),
+ 1usize,
+ concat!("Size of: ", stringify!(sentry))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<sentry>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(sentry))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const sentry)).i_am_plain_sentry as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(sentry),
+ "::",
+ stringify!(i_am_plain_sentry)
+ )
+ );
+ }
+ #[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::<NotTemplateWrapper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(NotTemplateWrapper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NotTemplateWrapper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(NotTemplateWrapper))
+ );
+ }
+ #[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() {
+ assert_eq!(
+ ::std::mem::size_of::<NotTemplateWrapper_sentry>(),
+ 1usize,
+ concat!("Size of: ", stringify!(NotTemplateWrapper_sentry))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NotTemplateWrapper_sentry>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry))
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const NotTemplateWrapper_sentry)).i_am_not_template_wrapper_sentry
+ as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(NotTemplateWrapper_sentry),
+ "::",
+ stringify!(i_am_not_template_wrapper_sentry)
+ )
+ );
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct InlineNotTemplateWrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct InlineNotTemplateWrapper_sentry {
+ pub i_am_inline_not_template_wrapper_sentry: bool,
+ }
+ #[test]
+ fn bindgen_test_layout_InlineNotTemplateWrapper_sentry() {
+ assert_eq!(
+ ::std::mem::size_of::<InlineNotTemplateWrapper_sentry>(),
+ 1usize,
+ concat!("Size of: ", stringify!(InlineNotTemplateWrapper_sentry))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<InlineNotTemplateWrapper_sentry>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(InlineNotTemplateWrapper_sentry))
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const InlineNotTemplateWrapper_sentry))
+ .i_am_inline_not_template_wrapper_sentry as *const _
+ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(InlineNotTemplateWrapper_sentry),
+ "::",
+ stringify!(i_am_inline_not_template_wrapper_sentry)
+ )
+ );
+ }
+ #[test]
+ fn bindgen_test_layout_InlineNotTemplateWrapper() {
+ assert_eq!(
+ ::std::mem::size_of::<InlineNotTemplateWrapper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(InlineNotTemplateWrapper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<InlineNotTemplateWrapper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(InlineNotTemplateWrapper))
+ );
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct InlineTemplateWrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct InlineTemplateWrapper_sentry {
+ pub i_am_inline_template_wrapper_sentry: ::std::os::raw::c_int,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct OuterDoubleWrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct OuterDoubleWrapper_InnerDoubleWrapper {
+ pub _address: u8,
+ }
+ #[test]
+ fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper() {
+ assert_eq!(
+ ::std::mem::size_of::<OuterDoubleWrapper_InnerDoubleWrapper>(),
+ 1usize,
+ concat!(
+ "Size of: ",
+ stringify!(OuterDoubleWrapper_InnerDoubleWrapper)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<OuterDoubleWrapper_InnerDoubleWrapper>(),
+ 1usize,
+ concat!(
+ "Alignment of ",
+ stringify!(OuterDoubleWrapper_InnerDoubleWrapper)
+ )
+ );
+ }
+ #[test]
+ fn bindgen_test_layout_OuterDoubleWrapper() {
+ assert_eq!(
+ ::std::mem::size_of::<OuterDoubleWrapper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(OuterDoubleWrapper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<OuterDoubleWrapper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(OuterDoubleWrapper))
+ );
+ }
+ #[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() {
+ assert_eq!(
+ ::std::mem::size_of::<OuterDoubleWrapper_InnerDoubleWrapper_sentry>(),
+ 4usize,
+ concat!(
+ "Size of: ",
+ stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<OuterDoubleWrapper_InnerDoubleWrapper_sentry>(),
+ 4usize,
+ concat!(
+ "Alignment of ",
+ stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(0 as *const OuterDoubleWrapper_InnerDoubleWrapper_sentry))
+ .i_am_double_wrapper_sentry as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry),
+ "::",
+ stringify!(i_am_double_wrapper_sentry)
+ )
+ );
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct OuterDoubleInlineWrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct OuterDoubleInlineWrapper_InnerDoubleInlineWrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ 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() {
+ 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 {
+ &(*(0 as *const OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))
+ .i_am_double_wrapper_inline_sentry as *const _ as usize
+ },
+ 0usize,
+ concat!(
+ "Alignment 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::<OuterDoubleInlineWrapper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(OuterDoubleInlineWrapper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<OuterDoubleInlineWrapper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper))
+ );
+ }
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct OutsideNamespaceWrapper {
+ pub _address: u8,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct OutsideNamespaceWrapper_sentry {
+ pub i_am_outside_namespace_wrapper_sentry: ::std::os::raw::c_int,
+ }
+ #[repr(C)]
+ #[derive(Debug, Default, Copy, Clone)]
+ pub struct sentry {
+ pub i_am_outside_namespace_sentry: ::std::os::raw::c_int,
+ }
+ #[test]
+ fn bindgen_test_layout_sentry() {
+ assert_eq!(
+ ::std::mem::size_of::<sentry>(),
+ 4usize,
+ concat!("Size of: ", stringify!(sentry))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<sentry>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(sentry))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const sentry)).i_am_outside_namespace_sentry as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(sentry),
+ "::",
+ stringify!(i_am_outside_namespace_sentry)
+ )
+ );
+ }
+}
diff --git a/tests/expectations/tests/short-enums.rs b/tests/expectations/tests/short-enums.rs
index 73eb45d7..c3b26da9 100644
--- a/tests/expectations/tests/short-enums.rs
+++ b/tests/expectations/tests/short-enums.rs
@@ -6,10 +6,16 @@
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum one_byte_t { SOME_VALUE = 1, }
+pub enum one_byte_t {
+ SOME_VALUE = 1,
+}
#[repr(u16)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum two_byte_t { SOME_OTHER_VALUE = 256, }
+pub enum two_byte_t {
+ SOME_OTHER_VALUE = 256,
+}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum four_byte_t { SOME_BIGGER_VALUE = 16777216, }
+pub enum four_byte_t {
+ SOME_BIGGER_VALUE = 16777216,
+}
diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs
index b3adbee6..9fa6c3ad 100644
--- a/tests/expectations/tests/size_t_template.rs
+++ b/tests/expectations/tests/size_t_template.rs
@@ -5,22 +5,25 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct C {
pub arr: [u32; 3usize],
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 12usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . arr as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( arr ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 12usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).arr as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(arr))
+ );
}
diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs
index db47ce6f..f20b9b3a 100644
--- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs
+++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs
@@ -5,45 +5,63 @@
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct a {
pub val_a: *mut b,
}
#[test]
fn bindgen_test_layout_a() {
- assert_eq!(::std::mem::size_of::<a>() , 8usize , concat ! (
- "Size of: " , stringify ! ( a ) ));
- assert_eq! (::std::mem::align_of::<a>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const a ) ) . val_a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( a ) , "::" , stringify
- ! ( val_a ) ));
-}
-impl Clone for a {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 8usize,
+ concat!("Size of: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const a)).val_a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(a),
+ "::",
+ stringify!(val_a)
+ )
+ );
}
impl Default for a {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct b {
pub val_b: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_b() {
- assert_eq!(::std::mem::size_of::<b>() , 4usize , concat ! (
- "Size of: " , stringify ! ( b ) ));
- assert_eq! (::std::mem::align_of::<b>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const b ) ) . val_b as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( b ) , "::" , stringify
- ! ( val_b ) ));
-}
-impl Clone for b {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<b>(),
+ 4usize,
+ concat!("Size of: ", stringify!(b))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<b>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const b)).val_b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(b),
+ "::",
+ stringify!(val_b)
+ )
+ );
}
diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs
index fb680b69..1079bb3f 100644
--- a/tests/expectations/tests/struct_typedef.rs
+++ b/tests/expectations/tests/struct_typedef.rs
@@ -5,57 +5,78 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct typedef_named_struct {
pub has_name: bool,
}
#[test]
fn bindgen_test_layout_typedef_named_struct() {
- assert_eq!(::std::mem::size_of::<typedef_named_struct>() , 1usize , concat
- ! ( "Size of: " , stringify ! ( typedef_named_struct ) ));
- assert_eq! (::std::mem::align_of::<typedef_named_struct>() , 1usize ,
- concat ! (
- "Alignment of " , stringify ! ( typedef_named_struct ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const typedef_named_struct ) ) . has_name as *
- const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( typedef_named_struct )
- , "::" , stringify ! ( has_name ) ));
-}
-impl Clone for typedef_named_struct {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<typedef_named_struct>(),
+ 1usize,
+ concat!("Size of: ", stringify!(typedef_named_struct))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<typedef_named_struct>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(typedef_named_struct))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const typedef_named_struct)).has_name as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(typedef_named_struct),
+ "::",
+ stringify!(has_name)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[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() {
- 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 {
- & ( * ( 0 as * const _bindgen_ty_1 ) ) . no_name as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
- , stringify ! ( no_name ) ));
-}
-impl Clone for _bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ 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 { &(*(0 as *const _bindgen_ty_1)).no_name as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(_bindgen_ty_1),
+ "::",
+ stringify!(no_name)
+ )
+ );
}
impl Default for _bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub type struct_ptr_t = *mut _bindgen_ty_1;
pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum typedef_named_enum { ENUM_HAS_NAME = 1, }
+pub enum typedef_named_enum {
+ ENUM_HAS_NAME = 1,
+}
pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _bindgen_ty_2 { ENUM_IS_ANON = 0, }
+pub enum _bindgen_ty_2 {
+ ENUM_IS_ANON = 0,
+}
pub type enum_ptr_t = *mut _bindgen_ty_2;
pub type enum_ptr_ptr_t = *mut *mut _bindgen_ty_2;
diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs
index e0dfe41d..b40c1733 100644
--- a/tests/expectations/tests/struct_typedef_ns.rs
+++ b/tests/expectations/tests/struct_typedef_ns.rs
@@ -12,7 +12,7 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+ #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct typedef_struct {
pub foo: ::std::os::raw::c_int,
}
@@ -39,11 +39,6 @@ pub mod root {
)
);
}
- impl Clone for typedef_struct {
- fn clone(&self) -> Self {
- *self
- }
- }
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum typedef_enum {
@@ -54,7 +49,7 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+ #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct _bindgen_ty_1 {
pub foo: ::std::os::raw::c_int,
}
@@ -81,11 +76,6 @@ pub mod root {
)
);
}
- impl Clone for _bindgen_ty_1 {
- fn clone(&self) -> Self {
- *self
- }
- }
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;
diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs
index 024eaac4..b8726df0 100644
--- a/tests/expectations/tests/struct_with_anon_struct.rs
+++ b/tests/expectations/tests/struct_with_anon_struct.rs
@@ -5,48 +5,69 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo {
pub bar: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs
index fe3e8b0c..8616ba5d 100644
--- a/tests/expectations/tests/struct_with_anon_struct_array.rs
+++ b/tests/expectations/tests/struct_with_anon_struct_array.rs
@@ -5,80 +5,119 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo {
pub bar: [foo__bindgen_ty_1; 2usize],
pub baz: [[[foo__bindgen_ty_2; 4usize]; 3usize]; 2usize],
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_2>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_2 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_2>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_2 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_2 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_2 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_2 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_2>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_2)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_2),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_2)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_2),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 208usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . baz as * const _ as usize } ,
- 16usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( baz ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 208usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).baz as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(baz)
+ )
+ );
}
diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs
index 006de1cd..733721be 100644
--- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs
+++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs
@@ -5,51 +5,74 @@
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo {
pub bar: *mut foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs
index a43ba4ee..716461ea 100644
--- a/tests/expectations/tests/struct_with_anon_union.rs
+++ b/tests/expectations/tests/struct_with_anon_union.rs
@@ -5,12 +5,12 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct foo {
pub bar: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1 {
pub a: ::std::os::raw::c_uint,
pub b: ::std::os::raw::c_ushort,
@@ -18,42 +18,67 @@ pub union foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for foo__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs
index 4a25fd6d..e02e78e9 100644
--- a/tests/expectations/tests/struct_with_anon_union_1_0.rs
+++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -49,36 +61,67 @@ pub struct foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs
index 0349d70c..839023ec 100644
--- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs
+++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs
@@ -5,43 +5,59 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo {
pub __bindgen_anon_1: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
}
diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs
index af25e4e4..3cb92db7 100644
--- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs
+++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs
@@ -5,12 +5,12 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct foo {
pub __bindgen_anon_1: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1 {
pub a: ::std::os::raw::c_uint,
pub b: ::std::os::raw::c_ushort,
@@ -18,37 +18,57 @@ pub union foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for foo__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs
index 5ce4064f..0f958b03 100644
--- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs
+++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -49,31 +61,57 @@ pub struct foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs
index 0581d4f2..9c7b3007 100644
--- a/tests/expectations/tests/struct_with_bitfields.rs
+++ b/tests/expectations/tests/struct_with_bitfields.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct bitfield {
pub _bitfield_1: u8,
pub e: ::std::os::raw::c_int,
@@ -34,11 +34,6 @@ fn bindgen_test_layout_bitfield() {
)
);
}
-impl Clone for bitfield {
- fn clone(&self) -> Self {
- *self
- }
-}
impl bitfield {
#[inline]
pub fn a(&self) -> ::std::os::raw::c_ushort {
@@ -50,13 +45,13 @@ impl bitfield {
::std::mem::size_of::<u8>(),
)
};
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_a(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 1u64 as u8;
+ let mask = 0x1 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -86,13 +81,13 @@ impl bitfield {
::std::mem::size_of::<u8>(),
)
};
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = (unit_field_val & mask) >> 1usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_b(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 2u64 as u8;
+ let mask = 0x2 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -122,13 +117,13 @@ impl bitfield {
::std::mem::size_of::<u8>(),
)
};
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = (unit_field_val & mask) >> 2usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_c(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 4u64 as u8;
+ let mask = 0x4 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -158,13 +153,13 @@ impl bitfield {
::std::mem::size_of::<u8>(),
)
};
- let mask = 192u64 as u8;
+ let mask = 0xc0 as u8;
let val = (unit_field_val & mask) >> 6usize;
unsafe { ::std::mem::transmute(val as u16) }
}
#[inline]
pub fn set_d(&mut self, val: ::std::os::raw::c_ushort) {
- let mask = 192u64 as u8;
+ let mask = 0xc0 as u8;
let val = val as u16 as u8;
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -191,10 +186,10 @@ impl bitfield {
c: ::std::os::raw::c_ushort,
d: ::std::os::raw::c_ushort,
) -> u8 {
- ((((0 | ((a as u16 as u8) << 0usize) & (1u64 as u8)) |
- ((b as u16 as u8) << 1usize) & (2u64 as u8)) |
- ((c as u16 as u8) << 2usize) & (4u64 as u8)) |
- ((d as u16 as u8) << 6usize) & (192u64 as u8))
+ ((((0 | ((a as u16 as u8) << 0usize) & (0x1 as u8))
+ | ((b as u16 as u8) << 1usize) & (0x2 as u8))
+ | ((c as u16 as u8) << 2usize) & (0x4 as u8))
+ | ((d as u16 as u8) << 6usize) & (0xc0 as u8))
}
#[inline]
pub fn f(&self) -> ::std::os::raw::c_uint {
@@ -206,13 +201,13 @@ impl bitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 3u64 as u64;
+ let mask = 0x3 as u64;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_f(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 3u64 as u64;
+ let mask = 0x3 as u64;
let val = val as u32 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -242,13 +237,13 @@ impl bitfield {
::std::mem::size_of::<u64>(),
)
};
- let mask = 18446744069414584320u64 as u64;
+ let mask = 0xffffffff00000000 as u64;
let val = (unit_field_val & mask) >> 32usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_g(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 18446744069414584320u64 as u64;
+ let mask = 0xffffffff00000000 as u64;
let val = val as u32 as u64;
let mut unit_field_val: u64 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -270,7 +265,7 @@ impl bitfield {
}
#[inline]
pub fn new_bitfield_2(f: ::std::os::raw::c_uint, g: ::std::os::raw::c_uint) -> u64 {
- ((0 | ((f as u32 as u64) << 0usize) & (3u64 as u64)) |
- ((g as u32 as u64) << 32usize) & (18446744069414584320u64 as u64))
+ ((0 | ((f as u32 as u64) << 0usize) & (0x3 as u64))
+ | ((g as u32 as u64) << 32usize) & (0xffffffff00000000 as u64))
}
}
diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs
index 03046674..4a068de5 100644
--- a/tests/expectations/tests/struct_with_derive_debug.rs
+++ b/tests/expectations/tests/struct_with_derive_debug.rs
@@ -5,88 +5,124 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct LittleArray {
pub a: [::std::os::raw::c_int; 32usize],
}
#[test]
fn bindgen_test_layout_LittleArray() {
- assert_eq!(::std::mem::size_of::<LittleArray>() , 128usize , concat ! (
- "Size of: " , stringify ! ( LittleArray ) ));
- assert_eq! (::std::mem::align_of::<LittleArray>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( LittleArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const LittleArray ) ) . a as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( LittleArray ) , "::" ,
- stringify ! ( a ) ));
-}
-impl Clone for LittleArray {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<LittleArray>(),
+ 128usize,
+ concat!("Size of: ", stringify!(LittleArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<LittleArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(LittleArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const LittleArray)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(LittleArray),
+ "::",
+ stringify!(a)
+ )
+ );
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct BigArray {
pub a: [::std::os::raw::c_int; 33usize],
}
#[test]
fn bindgen_test_layout_BigArray() {
- assert_eq!(::std::mem::size_of::<BigArray>() , 132usize , concat ! (
- "Size of: " , stringify ! ( BigArray ) ));
- assert_eq! (::std::mem::align_of::<BigArray>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( BigArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const BigArray ) ) . a as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( BigArray ) , "::" ,
- stringify ! ( a ) ));
-}
-impl Clone for BigArray {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<BigArray>(),
+ 132usize,
+ concat!("Size of: ", stringify!(BigArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BigArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(BigArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const BigArray)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(BigArray),
+ "::",
+ stringify!(a)
+ )
+ );
}
impl Default for BigArray {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct WithLittleArray {
pub a: LittleArray,
}
#[test]
fn bindgen_test_layout_WithLittleArray() {
- assert_eq!(::std::mem::size_of::<WithLittleArray>() , 128usize , concat !
- ( "Size of: " , stringify ! ( WithLittleArray ) ));
- assert_eq! (::std::mem::align_of::<WithLittleArray>() , 4usize , concat !
- ( "Alignment of " , stringify ! ( WithLittleArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithLittleArray ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithLittleArray ) ,
- "::" , stringify ! ( a ) ));
-}
-impl Clone for WithLittleArray {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<WithLittleArray>(),
+ 128usize,
+ concat!("Size of: ", stringify!(WithLittleArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithLittleArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithLittleArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithLittleArray)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithLittleArray),
+ "::",
+ stringify!(a)
+ )
+ );
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct WithBigArray {
pub a: BigArray,
}
#[test]
fn bindgen_test_layout_WithBigArray() {
- assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize , concat ! (
- "Size of: " , stringify ! ( WithBigArray ) ));
- assert_eq! (::std::mem::align_of::<WithBigArray>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
- stringify ! ( a ) ));
-}
-impl Clone for WithBigArray {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<WithBigArray>(),
+ 132usize,
+ concat!("Size of: ", stringify!(WithBigArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray),
+ "::",
+ stringify!(a)
+ )
+ );
}
impl Default for WithBigArray {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs
index 0f2accba..decc5934 100644
--- a/tests/expectations/tests/struct_with_large_array.rs
+++ b/tests/expectations/tests/struct_with_large_array.rs
@@ -5,33 +5,45 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct S {
pub large_array: [::std::os::raw::c_char; 33usize],
}
#[test]
fn bindgen_test_layout_S() {
- assert_eq!(::std::mem::size_of::<S>() , 33usize , concat ! (
- "Size of: " , stringify ! ( S ) ));
- assert_eq! (::std::mem::align_of::<S>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( S ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const S ) ) . large_array as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( S ) , "::" , stringify
- ! ( large_array ) ));
-}
-impl Clone for S {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<S>(),
+ 33usize,
+ concat!("Size of: ", stringify!(S))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<S>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(S))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const S)).large_array as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(S),
+ "::",
+ stringify!(large_array)
+ )
+ );
}
impl Default for S {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct ST<T> {
pub large_array: [T; 33usize],
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for ST<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for ST<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs
index 7b82964f..08fbc52c 100644
--- a/tests/expectations/tests/struct_with_nesting.rs
+++ b/tests/expectations/tests/struct_with_nesting.rs
@@ -5,13 +5,13 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub struct foo {
pub a: ::std::os::raw::c_uint,
pub __bindgen_anon_1: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1 {
pub b: ::std::os::raw::c_uint,
pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1,
@@ -19,39 +19,46 @@ pub union foo__bindgen_ty_1 {
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 2usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c2
- as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c2 )
- ));
-}
-impl Clone for foo__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).c1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(c1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).c2 as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(c2)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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,
@@ -60,75 +67,105 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 4usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 1usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d2
- as * const _ as usize } , 1usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d2 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d3
- as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d3 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d4
- as * const _ as usize } , 3usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d4 )
- ));
-}
-impl Clone for foo__bindgen_ty_1__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d2 as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d3 as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d3)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d4 as *const _ as usize },
+ 3usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d4)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for foo__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs
index 5d014b95..4701409a 100644
--- a/tests/expectations/tests/struct_with_nesting_1_0.rs
+++ b/tests/expectations/tests/struct_with_nesting_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -57,29 +69,41 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 4usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 2usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c2
- as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c2 )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).c1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(c1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).c2 as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(c2)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -91,69 +115,110 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 4usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 1usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d2
- as * const _ as usize } , 1usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d2 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d3
- as * const _ as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d3 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d4
- as * const _ as usize } , 3usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d4 )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d2 as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d3 as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d3)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).d4 as *const _ as usize },
+ 3usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(d4)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs
index 1b3f4ca2..b942ebd1 100644
--- a/tests/expectations/tests/struct_with_packing.rs
+++ b/tests/expectations/tests/struct_with_packing.rs
@@ -5,26 +5,31 @@
#[repr(C, packed)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct a {
pub b: ::std::os::raw::c_char,
pub c: ::std::os::raw::c_short,
}
#[test]
fn bindgen_test_layout_a() {
- assert_eq!(::std::mem::size_of::<a>() , 3usize , concat ! (
- "Size of: " , stringify ! ( a ) ));
- assert_eq! (::std::mem::align_of::<a>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( a ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . b as * const _ as usize
- } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( a ) , "::" , stringify
- ! ( b ) ));
- assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . c as * const _ as usize
- } , 1usize , concat ! (
- "Alignment of field: " , stringify ! ( a ) , "::" , stringify
- ! ( c ) ));
-}
-impl Clone for a {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<a>(),
+ 3usize,
+ concat!("Size of: ", stringify!(a))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<a>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const a)).b as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(a), "::", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const a)).c as *const _ as usize },
+ 1usize,
+ concat!("Alignment of field: ", stringify!(a), "::", stringify!(c))
+ );
}
diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs
index 47c99937..15494387 100644
--- a/tests/expectations/tests/struct_with_struct.rs
+++ b/tests/expectations/tests/struct_with_struct.rs
@@ -5,48 +5,69 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo {
pub bar: foo__bindgen_ty_1,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . x as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( x ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . y as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( y ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).x as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(x)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).y as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(y)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/tests/expectations/tests/struct_with_typedef_template_arg.rs
index ad4f394a..2c21656a 100644
--- a/tests/expectations/tests/struct_with_typedef_template_arg.rs
+++ b/tests/expectations/tests/struct_with_typedef_template_arg.rs
@@ -9,5 +9,4 @@
pub struct Proxy {
pub _address: u8,
}
-pub type Proxy_foo<T> =
- ::std::option::Option<unsafe extern "C" fn(bar: *mut T)>;
+pub type Proxy_foo<T> = ::std::option::Option<unsafe extern "C" fn(bar: *mut T)>;
diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs
index 8403f794..cce6c24d 100644
--- a/tests/expectations/tests/template-fun-ty.rs
+++ b/tests/expectations/tests/template-fun-ty.rs
@@ -9,8 +9,7 @@
pub struct Foo {
pub _address: u8,
}
-pub type Foo_FunctionPtr<T> =
- ::std::option::Option<unsafe extern "C" fn() -> T>;
+pub type Foo_FunctionPtr<T> = ::std::option::Option<unsafe extern "C" fn() -> T>;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RefPtr {
@@ -21,6 +20,7 @@ pub struct RefPtr {
pub struct RefPtr_Proxy {
pub _address: u8,
}
-pub type RefPtr_Proxy_member_function<R, Args> =
- ::std::option::Option<unsafe extern "C" fn(arg1: Args) -> R>;
+pub type RefPtr_Proxy_member_function<R, Args> = ::std::option::Option<
+ unsafe extern "C" fn(arg1: Args) -> R,
+>;
pub type Returner<T> = ::std::option::Option<unsafe extern "C" fn() -> T>;
diff --git a/tests/expectations/tests/template-param-usage-0.rs b/tests/expectations/tests/template-param-usage-0.rs
index 4f74a144..d5ca7d7d 100644
--- a/tests/expectations/tests/template-param-usage-0.rs
+++ b/tests/expectations/tests/template-param-usage-0.rs
@@ -10,6 +10,8 @@ pub struct UsesTemplateParameter<T> {
pub t: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for UsesTemplateParameter<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for UsesTemplateParameter<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-10.rs b/tests/expectations/tests/template-param-usage-10.rs
index a01597c1..940be664 100644
--- a/tests/expectations/tests/template-param-usage-10.rs
+++ b/tests/expectations/tests/template-param-usage-10.rs
@@ -21,9 +21,13 @@ pub struct DoublyIndirectUsage_IndirectUsage<T, U> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
-impl <T, U> Default for DoublyIndirectUsage_IndirectUsage<T, U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T, U> Default for DoublyIndirectUsage_IndirectUsage<T, U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-impl <T, U> Default for DoublyIndirectUsage<T, U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T, U> Default for DoublyIndirectUsage<T, U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-12.rs b/tests/expectations/tests/template-param-usage-12.rs
index 5912bdf5..d6a54085 100644
--- a/tests/expectations/tests/template-param-usage-12.rs
+++ b/tests/expectations/tests/template-param-usage-12.rs
@@ -10,8 +10,10 @@ pub struct BaseUsesT<T> {
pub t: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for BaseUsesT<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for BaseUsesT<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -20,6 +22,8 @@ pub struct CrtpUsesU<U> {
pub usage: U,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
-impl <U> Default for CrtpUsesU<U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<U> Default for CrtpUsesU<U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-13.rs b/tests/expectations/tests/template-param-usage-13.rs
index 4721968f..855c76fe 100644
--- a/tests/expectations/tests/template-param-usage-13.rs
+++ b/tests/expectations/tests/template-param-usage-13.rs
@@ -16,6 +16,8 @@ pub struct CrtpUsesU<U> {
pub usage: U,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
-impl <U> Default for CrtpUsesU<U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<U> Default for CrtpUsesU<U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-14.rs b/tests/expectations/tests/template-param-usage-14.rs
index d4c86652..97dbba46 100644
--- a/tests/expectations/tests/template-param-usage-14.rs
+++ b/tests/expectations/tests/template-param-usage-14.rs
@@ -16,5 +16,7 @@ pub struct CrtpIgnoresU {
pub y: ::std::os::raw::c_int,
}
impl Default for CrtpIgnoresU {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-15.rs b/tests/expectations/tests/template-param-usage-15.rs
index 9b7f30ec..405e8198 100644
--- a/tests/expectations/tests/template-param-usage-15.rs
+++ b/tests/expectations/tests/template-param-usage-15.rs
@@ -10,8 +10,10 @@ pub struct BaseUsesT<T> {
pub usage: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for BaseUsesT<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for BaseUsesT<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -20,5 +22,7 @@ pub struct CrtpIgnoresU {
pub y: ::std::os::raw::c_int,
}
impl Default for CrtpIgnoresU {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-2.rs b/tests/expectations/tests/template-param-usage-2.rs
index d017976b..24086724 100644
--- a/tests/expectations/tests/template-param-usage-2.rs
+++ b/tests/expectations/tests/template-param-usage-2.rs
@@ -16,9 +16,13 @@ pub struct UsesTemplateParameter_AlsoUsesTemplateParameter<T> {
pub also: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for UsesTemplateParameter_AlsoUsesTemplateParameter<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for UsesTemplateParameter_AlsoUsesTemplateParameter<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-impl <T> Default for UsesTemplateParameter<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for UsesTemplateParameter<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-3.rs b/tests/expectations/tests/template-param-usage-3.rs
index 85a96d54..0e5d2fdf 100644
--- a/tests/expectations/tests/template-param-usage-3.rs
+++ b/tests/expectations/tests/template-param-usage-3.rs
@@ -18,10 +18,13 @@ pub struct UsesTemplateParameter_AlsoUsesTemplateParameterAndMore<T, U> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
-impl <T, U> Default for
- UsesTemplateParameter_AlsoUsesTemplateParameterAndMore<T, U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T, U> Default for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore<T, U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-impl <T> Default for UsesTemplateParameter<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for UsesTemplateParameter<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-4.rs b/tests/expectations/tests/template-param-usage-4.rs
index 5e9e004c..af36754f 100644
--- a/tests/expectations/tests/template-param-usage-4.rs
+++ b/tests/expectations/tests/template-param-usage-4.rs
@@ -15,6 +15,8 @@ pub struct UsesTemplateParameter<T> {
pub struct UsesTemplateParameter_DoesNotUseTemplateParameters {
pub x: ::std::os::raw::c_int,
}
-impl <T> Default for UsesTemplateParameter<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for UsesTemplateParameter<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-5.rs b/tests/expectations/tests/template-param-usage-5.rs
index 375a60df..46ae3513 100644
--- a/tests/expectations/tests/template-param-usage-5.rs
+++ b/tests/expectations/tests/template-param-usage-5.rs
@@ -11,6 +11,8 @@ pub struct IndirectlyUsesTemplateParameter<T> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
pub type IndirectlyUsesTemplateParameter_Aliased<T> = T;
-impl <T> Default for IndirectlyUsesTemplateParameter<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for IndirectlyUsesTemplateParameter<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-7.rs b/tests/expectations/tests/template-param-usage-7.rs
index 38b3e832..b30c82b4 100644
--- a/tests/expectations/tests/template-param-usage-7.rs
+++ b/tests/expectations/tests/template-param-usage-7.rs
@@ -12,7 +12,9 @@ pub struct DoesNotUseU<T, V> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell<V>>,
}
-impl <T, V> Default for DoesNotUseU<T, V> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T, V> Default for DoesNotUseU<T, V> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub type Alias = DoesNotUseU<::std::os::raw::c_int, ::std::os::raw::c_char>;
diff --git a/tests/expectations/tests/template-param-usage-8.rs b/tests/expectations/tests/template-param-usage-8.rs
index 9a0f428f..75e14706 100644
--- a/tests/expectations/tests/template-param-usage-8.rs
+++ b/tests/expectations/tests/template-param-usage-8.rs
@@ -14,6 +14,8 @@ pub struct IndirectUsage<T, U> {
}
pub type IndirectUsage_Typedefed<T> = T;
pub type IndirectUsage_Aliased<U> = U;
-impl <T, U> Default for IndirectUsage<T, U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T, U> Default for IndirectUsage<T, U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template-param-usage-9.rs b/tests/expectations/tests/template-param-usage-9.rs
index 88fea725..3071924e 100644
--- a/tests/expectations/tests/template-param-usage-9.rs
+++ b/tests/expectations/tests/template-param-usage-9.rs
@@ -19,6 +19,8 @@ pub struct DoesNotUse_IndirectUsage<T, U> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
-impl <T, U> Default for DoesNotUse_IndirectUsage<T, U> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T, U> Default for DoesNotUse_IndirectUsage<T, U> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs
index 067ed380..999b81c7 100644
--- a/tests/expectations/tests/template.rs
+++ b/tests/expectations/tests/template.rs
@@ -29,7 +29,7 @@ impl<T> Default for B<T> {
}
}
extern "C" {
- #[link_name = "_Z3bar3FooIiiE"]
+ #[link_name = "\u{1}_Z3bar3FooIiiE"]
pub fn bar(foo: Foo<::std::os::raw::c_int>);
}
#[repr(C)]
@@ -38,7 +38,7 @@ pub struct mozilla_Foo {
_unused: [u8; 0],
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct C {
pub mB: B<::std::os::raw::c_uint>,
pub mBConstPtr: B<*const ::std::os::raw::c_int>,
@@ -214,11 +214,6 @@ fn bindgen_test_layout_C() {
)
);
}
-impl Clone for C {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for C {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -261,7 +256,7 @@ impl<T> Default for Rooted<T> {
}
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RootedContainer {
pub root: Rooted<*mut ::std::os::raw::c_void>,
}
@@ -288,11 +283,6 @@ fn bindgen_test_layout_RootedContainer() {
)
);
}
-impl Clone for RootedContainer {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for RootedContainer {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -346,9 +336,11 @@ impl Default for PODButContainsDtor {
/// <div rustbindgen opaque>
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
-pub struct Opaque {}
+pub struct Opaque {
+ pub _address: u8,
+}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct POD {
pub opaque_member: u32,
}
@@ -375,11 +367,6 @@ fn bindgen_test_layout_POD() {
)
);
}
-impl Clone for POD {
- fn clone(&self) -> Self {
- *self
- }
-}
/// <div rustbindgen replaces="NestedReplaced"></div>
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
@@ -411,7 +398,7 @@ pub struct NestedContainer<T> {
pub inc: Incomplete<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for NestedContainer<T> {
+impl<T> Default for NestedContainer<T> {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
@@ -422,13 +409,13 @@ pub struct Incomplete<T> {
pub d: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Incomplete<T> {
+impl<T> Default for Incomplete<T> {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Untemplated {
pub _address: u8,
}
@@ -445,11 +432,6 @@ fn bindgen_test_layout_Untemplated() {
concat!("Alignment of ", stringify!(Untemplated))
);
}
-impl Clone for Untemplated {
- fn clone(&self) -> Self {
- *self
- }
-}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Templated {
@@ -514,103 +496,367 @@ fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() {
24usize,
concat!(
"Size of template specialization: ",
- stringify ! ( Foo < :: std :: os :: raw :: c_int > )
+ stringify!(Foo<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo<::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(Foo<::std::os::raw::c_int>)
)
);
- assert_eq ! ( :: std :: mem :: align_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) );
}
#[test]
fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_uint > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_uint > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_uint > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_uint > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<::std::os::raw::c_uint>>(),
+ 4usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<::std::os::raw::c_uint>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<::std::os::raw::c_uint>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<::std::os::raw::c_uint>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*const ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*const ::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*const ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*const ::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * const mozilla_Foo > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const mozilla_Foo > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * const mozilla_Foo > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const mozilla_Foo > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*const mozilla_Foo>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*const mozilla_Foo>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*const mozilla_Foo>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*const mozilla_Foo>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < [ * const mozilla_Foo ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ * const mozilla_Foo ; 1usize ] > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < [ * const mozilla_Foo ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ * const mozilla_Foo ; 1usize ] > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<[*const mozilla_Foo; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<[*const mozilla_Foo; 1usize]>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<[*const mozilla_Foo; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<[*const mozilla_Foo; 1usize]>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < bool > > ( ) , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( B < bool > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < bool > > ( ) , 1usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < bool > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<bool>>(),
+ 1usize,
+ concat!("Size of template specialization: ", stringify!(B<bool>))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<bool>>(),
+ 1usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<bool>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < u16 > > ( ) , 2usize , concat ! ( "Size of template specialization: " , stringify ! ( B < u16 > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < u16 > > ( ) , 2usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < u16 > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<u16>>(),
+ 2usize,
+ concat!("Size of template specialization: ", stringify!(B<u16>))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<u16>>(),
+ 2usize,
+ concat!("Alignment of template specialization: ", stringify!(B<u16>))
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<[::std::os::raw::c_int; 1usize]>>(),
+ 4usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<[::std::os::raw::c_int; 1usize]>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<[::std::os::raw::c_int; 1usize]>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<[::std::os::raw::c_int; 1usize]>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < [ * mut :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<[*mut ::std::os::raw::c_int; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<[*mut ::std::os::raw::c_int; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*mut [::std::os::raw::c_int; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*mut [::std::os::raw::c_int; 1usize]>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*mut [::std::os::raw::c_int; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*mut [::std::os::raw::c_int; 1usize]>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*mut ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*mut ::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*mut ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*mut ::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * const :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * const :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*const ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*const ::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*const ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*const ::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * mut * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut * mut :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * mut * mut :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut * mut :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*mut *mut ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*mut *mut ::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*mut *mut ::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*mut *mut ::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( B < * mut [ :: std :: os :: raw :: c_int ; 1usize ] > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<B<*mut [::std::os::raw::c_int; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(B<*mut [::std::os::raw::c_int; 1usize]>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B<*mut [::std::os::raw::c_int; 1usize]>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(B<*mut [::std::os::raw::c_int; 1usize]>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() {
- assert_eq ! ( :: std :: mem :: size_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < Foo < :: std :: os :: raw :: c_int > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Foo < :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<Foo<::std::os::raw::c_int>>(),
+ 24usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(Foo<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo<::std::os::raw::c_int>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(Foo<::std::os::raw::c_int>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>(),
+ 24usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(Rooted<*mut ::std::os::raw::c_void>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Rooted<*mut ::std::os::raw::c_void>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(Rooted<*mut ::std::os::raw::c_void>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() {
- assert_eq ! ( :: std :: mem :: size_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < Rooted < * mut :: std :: os :: raw :: c_void > > ( ) , 8usize , concat ! ( "Alignment of template specialization: " , stringify ! ( Rooted < * mut :: std :: os :: raw :: c_void > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>(),
+ 24usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(Rooted<*mut ::std::os::raw::c_void>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Rooted<*mut ::std::os::raw::c_void>>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(Rooted<*mut ::std::os::raw::c_void>)
+ )
+ );
}
#[test]
fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() {
- assert_eq ! ( :: std :: mem :: size_of :: < WithDtor < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( WithDtor < :: std :: os :: raw :: c_int > ) ) );
- assert_eq ! ( :: std :: mem :: align_of :: < WithDtor < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( WithDtor < :: std :: os :: raw :: c_int > ) ) );
+ assert_eq!(
+ ::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(WithDtor<::std::os::raw::c_int>)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithDtor<::std::os::raw::c_int>>(),
+ 4usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(WithDtor<::std::os::raw::c_int>)
+ )
+ );
}
diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs
index c3f080db..9b66adf6 100644
--- a/tests/expectations/tests/template_alias.rs
+++ b/tests/expectations/tests/template_alias.rs
@@ -11,6 +11,8 @@ pub struct JS_Rooted<T> {
pub ptr: JS_detail_Wrapped<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for JS_Rooted<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for JS_Rooted<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs
index a9cd315d..dc03a231 100644
--- a/tests/expectations/tests/template_alias_namespace.rs
+++ b/tests/expectations/tests/template_alias_namespace.rs
@@ -22,8 +22,10 @@ pub mod root {
pub ptr: root::JS::detail::Wrapped<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
- impl <T> Default for Rooted<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ impl<T> Default for Rooted<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
}
}
diff --git a/tests/expectations/tests/template_partial_specification.rs b/tests/expectations/tests/template_partial_specification.rs
index 2ca90d40..5dcc6c40 100644
--- a/tests/expectations/tests/template_partial_specification.rs
+++ b/tests/expectations/tests/template_partial_specification.rs
@@ -2,6 +2,3 @@
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
-
diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs
index 7768d522..311dd974 100644
--- a/tests/expectations/tests/template_typedef_transitive_param.rs
+++ b/tests/expectations/tests/template_typedef_transitive_param.rs
@@ -15,7 +15,9 @@ pub struct Wrapper_Wrapped<T> {
pub t: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Wrapper_Wrapped<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Wrapper_Wrapped<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub type Wrapper_Type<T> = Wrapper_Wrapped<T>;
diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs
index 5f009f85..b6ab186a 100644
--- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs
+++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs
@@ -1,19 +1,18 @@
/* automatically generated by rust-bindgen */
extern "C" {
- #[link_name = "foo"]
+ #[link_name = "\u{1}foo"]
pub static mut foo:
- ::std::option::Option<unsafe extern "C" fn(x:
- ::std::os::raw::c_int,
- y:
- ::std::os::raw::c_int)
- -> ::std::os::raw::c_int>;
+ ::std::option::Option<
+ unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int)
+ -> ::std::os::raw::c_int,
+ >;
}
pub type Char = ::std::os::raw::c_char;
pub type SChar = ::std::os::raw::c_schar;
pub type UChar = ::std::os::raw::c_uchar;
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Test {
pub ch: ::std::os::raw::c_char,
pub u: ::std::os::raw::c_uchar,
@@ -30,71 +29,134 @@ pub struct Test {
}
#[test]
fn bindgen_test_layout_Test() {
- assert_eq!(::std::mem::size_of::<Test>() , 12usize , concat ! (
- "Size of: " , stringify ! ( Test ) ));
- assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Test ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . ch as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( ch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . u as * const _ as usize } ,
- 1usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( u ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . d as * const _ as usize } ,
- 2usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( d ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . cch as * const _ as usize } ,
- 3usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( cch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . cu as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( cu ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . cd as * const _ as usize } ,
- 5usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( cd ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Cch as * const _ as usize } ,
- 6usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Cch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Cu as * const _ as usize } ,
- 7usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Cu ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Cd as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Cd ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Ccch as * const _ as usize } ,
- 9usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Ccch ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Ccu as * const _ as usize } ,
- 10usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Ccu ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . Ccd as * const _ as usize } ,
- 11usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( Ccd ) ));
-}
-impl Clone for Test {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test>(),
+ 12usize,
+ concat!("Size of: ", stringify!(Test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Test))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).ch as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(ch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).u as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(u)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).d as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(d)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).cch as *const _ as usize },
+ 3usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(cch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).cu as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(cu)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).cd as *const _ as usize },
+ 5usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(cd)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Cch as *const _ as usize },
+ 6usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Cch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Cu as *const _ as usize },
+ 7usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Cu)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Cd as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Cd)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Ccch as *const _ as usize },
+ 9usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Ccch)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Ccu as *const _ as usize },
+ 10usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Ccu)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).Ccd as *const _ as usize },
+ 11usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(Ccd)
+ )
+ );
}
diff --git a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs
index 63d64654..73902a42 100644
--- a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs
+++ b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs
@@ -5,24 +5,32 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct dl_phdr_info {
pub x: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_dl_phdr_info() {
- assert_eq!(::std::mem::size_of::<dl_phdr_info>() , 4usize , concat ! (
- "Size of: " , stringify ! ( dl_phdr_info ) ));
- assert_eq! (::std::mem::align_of::<dl_phdr_info>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( dl_phdr_info ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const dl_phdr_info ) ) . x as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( dl_phdr_info ) , "::" ,
- stringify ! ( x ) ));
-}
-impl Clone for dl_phdr_info {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<dl_phdr_info>(),
+ 4usize,
+ concat!("Size of: ", stringify!(dl_phdr_info))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<dl_phdr_info>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(dl_phdr_info))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const dl_phdr_info)).x as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(dl_phdr_info),
+ "::",
+ stringify!(x)
+ )
+ );
}
extern "C" {
pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int;
diff --git a/tests/expectations/tests/type_alias_partial_template_especialization.rs b/tests/expectations/tests/type_alias_partial_template_especialization.rs
index 21d198a6..0a2e80fb 100644
--- a/tests/expectations/tests/type_alias_partial_template_especialization.rs
+++ b/tests/expectations/tests/type_alias_partial_template_especialization.rs
@@ -11,6 +11,8 @@ pub struct Rooted<T> {
pub ptr: MaybeWrapped<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Rooted<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Rooted<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs
index 2bbdcbb1..7376aa76 100644
--- a/tests/expectations/tests/typeref.rs
+++ b/tests/expectations/tests/typeref.rs
@@ -5,41 +5,50 @@
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct mozilla_FragmentOrURL {
pub mIsLocalRef: bool,
}
#[test]
fn bindgen_test_layout_mozilla_FragmentOrURL() {
- assert_eq!(::std::mem::size_of::<mozilla_FragmentOrURL>() , 1usize ,
- concat ! ( "Size of: " , stringify ! ( mozilla_FragmentOrURL )
- ));
- assert_eq! (::std::mem::align_of::<mozilla_FragmentOrURL>() , 1usize ,
- concat ! (
- "Alignment of " , stringify ! ( mozilla_FragmentOrURL ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const mozilla_FragmentOrURL ) ) . mIsLocalRef
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( mozilla_FragmentOrURL )
- , "::" , stringify ! ( mIsLocalRef ) ));
-}
-impl Clone for mozilla_FragmentOrURL {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<mozilla_FragmentOrURL>(),
+ 1usize,
+ concat!("Size of: ", stringify!(mozilla_FragmentOrURL))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mozilla_FragmentOrURL>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(mozilla_FragmentOrURL))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const mozilla_FragmentOrURL)).mIsLocalRef as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(mozilla_FragmentOrURL),
+ "::",
+ stringify!(mIsLocalRef)
+ )
+ );
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[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::<mozilla_Position>() , 1usize , concat ! (
- "Size of: " , stringify ! ( mozilla_Position ) ));
- assert_eq! (::std::mem::align_of::<mozilla_Position>() , 1usize , concat !
- ( "Alignment of " , stringify ! ( mozilla_Position ) ));
-}
-impl Clone for mozilla_Position {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<mozilla_Position>(),
+ 1usize,
+ concat!("Size of: ", stringify!(mozilla_Position))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mozilla_Position>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(mozilla_Position))
+ );
}
#[repr(C)]
pub struct mozilla_StyleShapeSource {
@@ -52,33 +61,47 @@ pub union mozilla_StyleShapeSource__bindgen_ty_1 {
_bindgen_union_align: u64,
}
impl Default for mozilla_StyleShapeSource__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl Default for mozilla_StyleShapeSource {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Bar {
pub mFoo: *mut nsFoo,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . mFoo as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( mFoo ) ));
-}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).mFoo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(mFoo)
+ )
+ );
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct nsFoo {
@@ -86,27 +109,48 @@ pub struct nsFoo {
}
#[test]
fn bindgen_test_layout_nsFoo() {
- assert_eq!(::std::mem::size_of::<nsFoo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsFoo ) ));
- assert_eq! (::std::mem::align_of::<nsFoo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsFoo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsFoo ) ) . mBar as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsFoo ) , "::" ,
- stringify ! ( mBar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<nsFoo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsFoo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsFoo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsFoo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsFoo)).mBar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsFoo),
+ "::",
+ stringify!(mBar)
+ )
+ );
}
impl Default for nsFoo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<mozilla_StyleShapeSource>() , 8usize ,
- concat ! (
- "Size of template specialization: " , stringify ! (
- mozilla_StyleShapeSource ) ));
- assert_eq!(::std::mem::align_of::<mozilla_StyleShapeSource>() , 8usize ,
- concat ! (
- "Alignment of template specialization: " , stringify ! (
- mozilla_StyleShapeSource ) ));
+ assert_eq!(
+ ::std::mem::size_of::<mozilla_StyleShapeSource>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(mozilla_StyleShapeSource)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mozilla_StyleShapeSource>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(mozilla_StyleShapeSource)
+ )
+ );
}
diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs
index a99df0ad..6796ced8 100644
--- a/tests/expectations/tests/typeref_1_0.rs
+++ b/tests/expectations/tests/typeref_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct mozilla_FragmentOrURL {
@@ -42,20 +54,31 @@ pub struct mozilla_FragmentOrURL {
}
#[test]
fn bindgen_test_layout_mozilla_FragmentOrURL() {
- assert_eq!(::std::mem::size_of::<mozilla_FragmentOrURL>() , 1usize ,
- concat ! ( "Size of: " , stringify ! ( mozilla_FragmentOrURL )
- ));
- assert_eq! (::std::mem::align_of::<mozilla_FragmentOrURL>() , 1usize ,
- concat ! (
- "Alignment of " , stringify ! ( mozilla_FragmentOrURL ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const mozilla_FragmentOrURL ) ) . mIsLocalRef
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( mozilla_FragmentOrURL )
- , "::" , stringify ! ( mIsLocalRef ) ));
+ assert_eq!(
+ ::std::mem::size_of::<mozilla_FragmentOrURL>(),
+ 1usize,
+ concat!("Size of: ", stringify!(mozilla_FragmentOrURL))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mozilla_FragmentOrURL>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(mozilla_FragmentOrURL))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const mozilla_FragmentOrURL)).mIsLocalRef as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(mozilla_FragmentOrURL),
+ "::",
+ stringify!(mIsLocalRef)
+ )
+ );
}
impl Clone for mozilla_FragmentOrURL {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -64,13 +87,21 @@ pub struct mozilla_Position {
}
#[test]
fn bindgen_test_layout_mozilla_Position() {
- assert_eq!(::std::mem::size_of::<mozilla_Position>() , 1usize , concat ! (
- "Size of: " , stringify ! ( mozilla_Position ) ));
- assert_eq! (::std::mem::align_of::<mozilla_Position>() , 1usize , concat !
- ( "Alignment of " , stringify ! ( mozilla_Position ) ));
+ assert_eq!(
+ ::std::mem::size_of::<mozilla_Position>(),
+ 1usize,
+ concat!("Size of: ", stringify!(mozilla_Position))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mozilla_Position>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(mozilla_Position))
+ );
}
impl Clone for mozilla_Position {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
@@ -91,21 +122,36 @@ pub struct Bar {
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . mFoo as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( mFoo ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).mFoo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(mFoo)
+ )
+ );
}
impl Clone for Bar {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for Bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -114,27 +160,48 @@ pub struct nsFoo {
}
#[test]
fn bindgen_test_layout_nsFoo() {
- assert_eq!(::std::mem::size_of::<nsFoo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsFoo ) ));
- assert_eq! (::std::mem::align_of::<nsFoo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsFoo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsFoo ) ) . mBar as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsFoo ) , "::" ,
- stringify ! ( mBar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<nsFoo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsFoo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsFoo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsFoo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsFoo)).mBar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsFoo),
+ "::",
+ stringify!(mBar)
+ )
+ );
}
impl Clone for nsFoo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() {
- assert_eq!(::std::mem::size_of::<mozilla_StyleShapeSource>() , 8usize ,
- concat ! (
- "Size of template specialization: " , stringify ! (
- mozilla_StyleShapeSource ) ));
- assert_eq!(::std::mem::align_of::<mozilla_StyleShapeSource>() , 8usize ,
- concat ! (
- "Alignment of template specialization: " , stringify ! (
- mozilla_StyleShapeSource ) ));
+ assert_eq!(
+ ::std::mem::size_of::<mozilla_StyleShapeSource>(),
+ 8usize,
+ concat!(
+ "Size of template specialization: ",
+ stringify!(mozilla_StyleShapeSource)
+ )
+ );
+ assert_eq!(
+ ::std::mem::align_of::<mozilla_StyleShapeSource>(),
+ 8usize,
+ concat!(
+ "Alignment of template specialization: ",
+ stringify!(mozilla_StyleShapeSource)
+ )
+ );
}
diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs
new file mode 100644
index 00000000..d9c61f7b
--- /dev/null
+++ b/tests/expectations/tests/underscore.rs
@@ -0,0 +1,35 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const __: ::std::os::raw::c_int = 10;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct ptr_t {
+ pub __: [::std::os::raw::c_uchar; 8usize],
+}
+#[test]
+fn bindgen_test_layout_ptr_t() {
+ assert_eq!(
+ ::std::mem::size_of::<ptr_t>(),
+ 8usize,
+ concat!("Size of: ", stringify!(ptr_t))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ptr_t>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(ptr_t))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ptr_t)).__ as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ptr_t),
+ "::",
+ stringify!(__)
+ )
+ );
+}
diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs
index cb8779bd..9776626c 100644
--- a/tests/expectations/tests/union-in-ns.rs
+++ b/tests/expectations/tests/union-in-ns.rs
@@ -9,27 +9,37 @@ pub mod root {
#[allow(unused_imports)]
use self::super::root;
#[repr(C)]
- #[derive(Copy)]
+ #[derive(Copy, Clone)]
pub union bar {
pub baz: ::std::os::raw::c_int,
_bindgen_union_align: u32,
}
#[test]
fn bindgen_test_layout_bar() {
- assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( bar ) ));
- assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . baz as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( baz ) ));
- }
- impl Clone for bar {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(baz)
+ )
+ );
}
impl Default for bar {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
}
diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs
index b3618ab7..ec2014a5 100644
--- a/tests/expectations/tests/union-in-ns_1_0.rs
+++ b/tests/expectations/tests/union-in-ns_1_0.rs
@@ -8,39 +8,47 @@
pub mod root {
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
- impl <T> __BindgenUnionField<T> {
+ impl<T> __BindgenUnionField<T> {
#[inline]
pub fn new() -> Self {
__BindgenUnionField(::std::marker::PhantomData)
}
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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 <T> ::std::default::Default for __BindgenUnionField<T> {
+ impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
- impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+ impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
- impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
- impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+ impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+ impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
- impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+ impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
- impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+ impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
- impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+ impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[allow(unused_imports)]
use self::super::root;
#[repr(C)]
@@ -51,17 +59,30 @@ pub mod root {
}
#[test]
fn bindgen_test_layout_bar() {
- assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( bar ) ));
- assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const bar ) ) . baz as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( bar ) , "::" ,
- stringify ! ( baz ) ));
+ assert_eq!(
+ ::std::mem::size_of::<bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const bar)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(bar),
+ "::",
+ stringify!(baz)
+ )
+ );
}
impl Clone for bar {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
}
diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs
new file mode 100644
index 00000000..ee82188c
--- /dev/null
+++ b/tests/expectations/tests/union_bitfield.rs
@@ -0,0 +1,175 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union U4 {
+ pub _bitfield_1: u8,
+ _bindgen_union_align: u32,
+}
+#[test]
+fn bindgen_test_layout_U4() {
+ assert_eq!(
+ ::std::mem::size_of::<U4>(),
+ 4usize,
+ concat!("Size of: ", stringify!(U4))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<U4>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(U4))
+ );
+}
+impl Default for U4 {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl U4 {
+ #[inline]
+ pub fn derp(&self) -> ::std::os::raw::c_uint {
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ let mask = 0x1 as u8;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u32) }
+ }
+ #[inline]
+ pub fn set_derp(&mut self, val: ::std::os::raw::c_uint) {
+ let mask = 0x1 as u8;
+ let val = val as u32 as u8;
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(derp: ::std::os::raw::c_uint) -> u8 {
+ (0 | ((derp as u32 as u8) << 0usize) & (0x1 as u8))
+ }
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union B {
+ pub _bitfield_1: u32,
+ _bindgen_union_align: u32,
+}
+#[test]
+fn bindgen_test_layout_B() {
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 4usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(B))
+ );
+}
+impl Default for B {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl B {
+ #[inline]
+ pub fn foo(&self) -> ::std::os::raw::c_uint {
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ let mask = 0x7fffffff as u32;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u32) }
+ }
+ #[inline]
+ pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) {
+ let mask = 0x7fffffff as u32;
+ let val = val as u32 as u32;
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn bar(&self) -> ::std::os::raw::c_uchar {
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ let mask = 0x80000000 as u32;
+ let val = (unit_field_val & mask) >> 31usize;
+ unsafe { ::std::mem::transmute(val as u8) }
+ }
+ #[inline]
+ pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) {
+ let mask = 0x80000000 as u32;
+ let val = val as u8 as u32;
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 31usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar) -> u32 {
+ ((0 | ((foo as u32 as u32) << 0usize) & (0x7fffffff as u32))
+ | ((bar as u8 as u32) << 31usize) & (0x80000000 as u32))
+ }
+}
diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/tests/expectations/tests/union_bitfield_1_0.rs
new file mode 100644
index 00000000..4b7885d2
--- /dev/null
+++ b/tests/expectations/tests/union_bitfield_1_0.rs
@@ -0,0 +1,242 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
+impl<T> __BindgenUnionField<T> {
+ #[inline]
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
+ #[inline]
+ pub unsafe fn as_ref(&self) -> &T {
+ ::std::mem::transmute(self)
+ }
+ #[inline]
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
+}
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
+ #[inline]
+ fn default() -> Self {
+ Self::new()
+ }
+}
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
+ #[inline]
+ fn clone(&self) -> Self {
+ Self::new()
+ }
+}
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__BindgenUnionField")
+ }
+}
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
+}
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
+}
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+pub struct U4 {
+ pub _bitfield_1: __BindgenUnionField<u8>,
+ pub bindgen_union_field: u32,
+}
+#[test]
+fn bindgen_test_layout_U4() {
+ assert_eq!(
+ ::std::mem::size_of::<U4>(),
+ 4usize,
+ concat!("Size of: ", stringify!(U4))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<U4>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(U4))
+ );
+}
+impl Clone for U4 {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+impl U4 {
+ #[inline]
+ pub fn derp(&self) -> ::std::os::raw::c_uint {
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ let mask = 0x1 as u8;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u32) }
+ }
+ #[inline]
+ pub fn set_derp(&mut self, val: ::std::os::raw::c_uint) {
+ let mask = 0x1 as u8;
+ let val = val as u32 as u8;
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(derp: ::std::os::raw::c_uint) -> u8 {
+ (0 | ((derp as u32 as u8) << 0usize) & (0x1 as u8))
+ }
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+pub struct B {
+ pub _bitfield_1: __BindgenUnionField<u32>,
+ pub bindgen_union_field: u32,
+}
+#[test]
+fn bindgen_test_layout_B() {
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 4usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(B))
+ );
+}
+impl Clone for B {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+impl B {
+ #[inline]
+ pub fn foo(&self) -> ::std::os::raw::c_uint {
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ let mask = 0x7fffffff as u32;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u32) }
+ }
+ #[inline]
+ pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) {
+ let mask = 0x7fffffff as u32;
+ let val = val as u32 as u32;
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn bar(&self) -> ::std::os::raw::c_uchar {
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ let mask = 0x80000000 as u32;
+ let val = (unit_field_val & mask) >> 31usize;
+ unsafe { ::std::mem::transmute(val as u8) }
+ }
+ #[inline]
+ pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) {
+ let mask = 0x80000000 as u32;
+ let val = val as u8 as u32;
+ let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u32 as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 31usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u32>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar) -> u32 {
+ ((0 | ((foo as u32 as u32) << 0usize) & (0x7fffffff as u32))
+ | ((bar as u8 as u32) << 31usize) & (0x80000000 as u32))
+ }
+}
+#[repr(C)]
+#[derive(Copy)]
+pub struct HasBigBitfield {
+ pub _bitfield_1: __BindgenUnionField<[u8; 16usize]>,
+ pub bindgen_union_field: [u8; 16usize],
+}
+#[test]
+fn bindgen_test_layout_HasBigBitfield() {
+ assert_eq!(
+ ::std::mem::size_of::<HasBigBitfield>(),
+ 16usize,
+ concat!("Size of: ", stringify!(HasBigBitfield))
+ );
+}
+impl Clone for HasBigBitfield {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+impl Default for HasBigBitfield {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs
index a0404ac9..e62521bc 100644
--- a/tests/expectations/tests/union_dtor.rs
+++ b/tests/expectations/tests/union_dtor.rs
@@ -12,27 +12,45 @@ pub union UnionWithDtor {
}
#[test]
fn bindgen_test_layout_UnionWithDtor() {
- assert_eq!(::std::mem::size_of::<UnionWithDtor>() , 8usize , concat ! (
- "Size of: " , stringify ! ( UnionWithDtor ) ));
- assert_eq! (::std::mem::align_of::<UnionWithDtor>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( UnionWithDtor ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UnionWithDtor ) ) . mFoo as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( UnionWithDtor ) , "::"
- , stringify ! ( mFoo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UnionWithDtor ) ) . mBar as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( UnionWithDtor ) , "::"
- , stringify ! ( mBar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<UnionWithDtor>(),
+ 8usize,
+ concat!("Size of: ", stringify!(UnionWithDtor))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<UnionWithDtor>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(UnionWithDtor))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UnionWithDtor)).mFoo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UnionWithDtor),
+ "::",
+ stringify!(mFoo)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UnionWithDtor)).mBar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UnionWithDtor),
+ "::",
+ stringify!(mBar)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZN13UnionWithDtorD1Ev"]
+ #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"]
pub fn UnionWithDtor_UnionWithDtor_destructor(this: *mut UnionWithDtor);
}
impl Default for UnionWithDtor {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl UnionWithDtor {
#[inline]
diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs
index 2c8f80d7..f7896dc7 100644
--- a/tests/expectations/tests/union_dtor_1_0.rs
+++ b/tests/expectations/tests/union_dtor_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default)]
pub struct UnionWithDtor {
@@ -44,23 +56,39 @@ pub struct UnionWithDtor {
}
#[test]
fn bindgen_test_layout_UnionWithDtor() {
- assert_eq!(::std::mem::size_of::<UnionWithDtor>() , 8usize , concat ! (
- "Size of: " , stringify ! ( UnionWithDtor ) ));
- assert_eq! (::std::mem::align_of::<UnionWithDtor>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( UnionWithDtor ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UnionWithDtor ) ) . mFoo as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( UnionWithDtor ) , "::"
- , stringify ! ( mFoo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const UnionWithDtor ) ) . mBar as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( UnionWithDtor ) , "::"
- , stringify ! ( mBar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<UnionWithDtor>(),
+ 8usize,
+ concat!("Size of: ", stringify!(UnionWithDtor))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<UnionWithDtor>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(UnionWithDtor))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UnionWithDtor)).mFoo as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UnionWithDtor),
+ "::",
+ stringify!(mFoo)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const UnionWithDtor)).mBar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(UnionWithDtor),
+ "::",
+ stringify!(mBar)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZN13UnionWithDtorD1Ev"]
+ #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"]
pub fn UnionWithDtor_UnionWithDtor_destructor(this: *mut UnionWithDtor);
}
impl UnionWithDtor {
diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs
index 90319ee6..0c723b2a 100644
--- a/tests/expectations/tests/union_fields.rs
+++ b/tests/expectations/tests/union_fields.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union nsStyleUnion {
pub mInt: ::std::os::raw::c_int,
pub mFloat: f32,
@@ -14,29 +14,49 @@ pub union nsStyleUnion {
}
#[test]
fn bindgen_test_layout_nsStyleUnion() {
- assert_eq!(::std::mem::size_of::<nsStyleUnion>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsStyleUnion ) ));
- assert_eq! (::std::mem::align_of::<nsStyleUnion>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsStyleUnion ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsStyleUnion ) ) . mInt as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" ,
- stringify ! ( mInt ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsStyleUnion ) ) . mFloat as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" ,
- stringify ! ( mFloat ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsStyleUnion ) ) . mPointer as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" ,
- stringify ! ( mPointer ) ));
-}
-impl Clone for nsStyleUnion {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<nsStyleUnion>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsStyleUnion))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsStyleUnion>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsStyleUnion))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsStyleUnion)).mInt as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsStyleUnion),
+ "::",
+ stringify!(mInt)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsStyleUnion)).mFloat as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsStyleUnion),
+ "::",
+ stringify!(mFloat)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsStyleUnion)).mPointer as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsStyleUnion),
+ "::",
+ stringify!(mPointer)
+ )
+ );
}
impl Default for nsStyleUnion {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs
index 3f244b78..1e10ff97 100644
--- a/tests/expectations/tests/union_fields_1_0.rs
+++ b/tests/expectations/tests/union_fields_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq)]
pub struct nsStyleUnion {
@@ -45,26 +57,49 @@ pub struct nsStyleUnion {
}
#[test]
fn bindgen_test_layout_nsStyleUnion() {
- assert_eq!(::std::mem::size_of::<nsStyleUnion>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsStyleUnion ) ));
- assert_eq! (::std::mem::align_of::<nsStyleUnion>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsStyleUnion ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsStyleUnion ) ) . mInt as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" ,
- stringify ! ( mInt ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsStyleUnion ) ) . mFloat as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" ,
- stringify ! ( mFloat ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const nsStyleUnion ) ) . mPointer as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( nsStyleUnion ) , "::" ,
- stringify ! ( mPointer ) ));
+ assert_eq!(
+ ::std::mem::size_of::<nsStyleUnion>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsStyleUnion))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsStyleUnion>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsStyleUnion))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsStyleUnion)).mInt as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsStyleUnion),
+ "::",
+ stringify!(mInt)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsStyleUnion)).mFloat as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsStyleUnion),
+ "::",
+ stringify!(mFloat)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const nsStyleUnion)).mPointer as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(nsStyleUnion),
+ "::",
+ stringify!(mPointer)
+ )
+ );
}
impl Clone for nsStyleUnion {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs
index f6418fd6..515d5688 100644
--- a/tests/expectations/tests/union_template.rs
+++ b/tests/expectations/tests/union_template.rs
@@ -17,7 +17,9 @@ pub union NastyStruct__bindgen_ty_1 {
_bindgen_union_align: u64,
}
impl Default for NastyStruct__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub union NastyStruct__bindgen_ty_2 {
@@ -26,10 +28,14 @@ pub union NastyStruct__bindgen_ty_2 {
_bindgen_union_align: u64,
}
impl Default for NastyStruct__bindgen_ty_2 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
impl Default for NastyStruct {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub union Whatever {
@@ -38,5 +44,7 @@ pub union Whatever {
_bindgen_union_align: u64,
}
impl Default for Whatever {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_template_1_0.rs b/tests/expectations/tests/union_template_1_0.rs
index afe14c70..7b350b07 100644
--- a/tests/expectations/tests/union_template_1_0.rs
+++ b/tests/expectations/tests/union_template_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct NastyStruct {
diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs
index d48538a0..87bcf6f3 100644
--- a/tests/expectations/tests/union_with_anon_struct.rs
+++ b/tests/expectations/tests/union_with_anon_struct.rs
@@ -5,52 +5,75 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo {
pub bar: foo__bindgen_ty_1,
_bindgen_union_align: [u32; 2usize],
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, 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() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs
index 8c0971f7..b79be127 100644
--- a/tests/expectations/tests/union_with_anon_struct_1_0.rs
+++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -49,36 +61,67 @@ pub struct foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 4usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs
index 3c903028..ef5c1670 100644
--- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs
+++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs
@@ -5,14 +5,14 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo {
pub a: ::std::os::raw::c_int,
pub __bindgen_anon_1: foo__bindgen_ty_1,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo__bindgen_ty_1 {
pub _bitfield_1: u32,
pub __bindgen_align: [u32; 0usize],
@@ -30,11 +30,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() {
concat!("Alignment of ", stringify!(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 {
@@ -46,13 +41,13 @@ impl foo__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 127u64 as u32;
+ let mask = 0x7f as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b(&mut self, val: ::std::os::raw::c_int) {
- let mask = 127u64 as u32;
+ let mask = 0x7f as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -82,13 +77,13 @@ impl foo__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 4294967168u64 as u32;
+ let mask = 0xffffff80 as u32;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_c(&mut self, val: ::std::os::raw::c_int) {
- let mask = 4294967168u64 as u32;
+ let mask = 0xffffff80 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -110,8 +105,8 @@ impl foo__bindgen_ty_1 {
}
#[inline]
pub fn new_bitfield_1(b: ::std::os::raw::c_int, c: ::std::os::raw::c_int) -> u32 {
- ((0 | ((b as u32 as u32) << 0usize) & (127u64 as u32)) |
- ((c as u32 as u32) << 7usize) & (4294967168u64 as u32))
+ ((0 | ((b as u32 as u32) << 0usize) & (0x7f as u32))
+ | ((c as u32 as u32) << 7usize) & (0xffffff80 as u32))
}
}
#[test]
@@ -132,11 +127,6 @@ fn bindgen_test_layout_foo() {
concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
);
}
-impl Clone for foo {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for foo {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs
index 2b5ffbac..803d6cde 100644
--- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs
+++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs
@@ -46,7 +46,7 @@ impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
true
}
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -89,13 +89,13 @@ impl foo__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 127u64 as u32;
+ let mask = 0x7f as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_b(&mut self, val: ::std::os::raw::c_int) {
- let mask = 127u64 as u32;
+ let mask = 0x7f as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -125,13 +125,13 @@ impl foo__bindgen_ty_1 {
::std::mem::size_of::<u32>(),
)
};
- let mask = 4294967168u64 as u32;
+ let mask = 0xffffff80 as u32;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_c(&mut self, val: ::std::os::raw::c_int) {
- let mask = 4294967168u64 as u32;
+ let mask = 0xffffff80 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -153,8 +153,8 @@ impl foo__bindgen_ty_1 {
}
#[inline]
pub fn new_bitfield_1(b: ::std::os::raw::c_int, c: ::std::os::raw::c_int) -> u32 {
- ((0 | ((b as u32 as u32) << 0usize) & (127u64 as u32)) |
- ((c as u32 as u32) << 7usize) & (4294967168u64 as u32))
+ ((0 | ((b as u32 as u32) << 0usize) & (0x7f as u32))
+ | ((c as u32 as u32) << 7usize) & (0xffffff80 as u32))
}
}
#[test]
diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs
index 29dbe7dc..92f85595 100644
--- a/tests/expectations/tests/union_with_anon_union.rs
+++ b/tests/expectations/tests/union_with_anon_union.rs
@@ -5,13 +5,13 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo {
pub bar: foo__bindgen_ty_1,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1 {
pub a: ::std::os::raw::c_uint,
pub b: ::std::os::raw::c_ushort,
@@ -19,42 +19,67 @@ pub union foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for foo__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs
index 62a62f85..958d8e67 100644
--- a/tests/expectations/tests/union_with_anon_union_1_0.rs
+++ b/tests/expectations/tests/union_with_anon_union_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -50,36 +62,67 @@ pub struct foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs
index 61b36d1a..1f5e493f 100644
--- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs
+++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs
@@ -5,14 +5,14 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union pixel {
pub rgba: ::std::os::raw::c_uint,
pub __bindgen_anon_1: pixel__bindgen_ty_1,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
pub struct pixel__bindgen_ty_1 {
pub r: ::std::os::raw::c_uchar,
pub g: ::std::os::raw::c_uchar,
@@ -21,50 +21,82 @@ pub struct pixel__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_pixel__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<pixel__bindgen_ty_1>() , 4usize , concat
- ! ( "Size of: " , stringify ! ( pixel__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<pixel__bindgen_ty_1>() , 1usize ,
- concat ! (
- "Alignment of " , stringify ! ( pixel__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . r as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( r ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . g as * const _
- as usize } , 1usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( g ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . b as * const _
- as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . a as * const _
- as usize } , 3usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
-}
-impl Clone for pixel__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<pixel__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(pixel__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<pixel__bindgen_ty_1>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(pixel__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).r as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(r)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).g as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(g)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).b as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).a as *const _ as usize },
+ 3usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
}
#[test]
fn bindgen_test_layout_pixel() {
- assert_eq!(::std::mem::size_of::<pixel>() , 4usize , concat ! (
- "Size of: " , stringify ! ( pixel ) ));
- assert_eq! (::std::mem::align_of::<pixel>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( pixel ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel ) ) . rgba as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel ) , "::" ,
- stringify ! ( rgba ) ));
-}
-impl Clone for pixel {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<pixel>(),
+ 4usize,
+ concat!("Size of: ", stringify!(pixel))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<pixel>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(pixel))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel)).rgba as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel),
+ "::",
+ stringify!(rgba)
+ )
+ );
}
impl Default for pixel {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs
index 45d824ba..d0dc0088 100644
--- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs
+++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct pixel {
@@ -52,47 +64,87 @@ pub struct pixel__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_pixel__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<pixel__bindgen_ty_1>() , 4usize , concat
- ! ( "Size of: " , stringify ! ( pixel__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<pixel__bindgen_ty_1>() , 1usize ,
- concat ! (
- "Alignment of " , stringify ! ( pixel__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . r as * const _
- as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( r ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . g as * const _
- as usize } , 1usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( g ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . b as * const _
- as usize } , 2usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . a as * const _
- as usize } , 3usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) ,
- "::" , stringify ! ( a ) ));
+ assert_eq!(
+ ::std::mem::size_of::<pixel__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(pixel__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<pixel__bindgen_ty_1>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(pixel__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).r as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(r)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).g as *const _ as usize },
+ 1usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(g)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).b as *const _ as usize },
+ 2usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel__bindgen_ty_1)).a as *const _ as usize },
+ 3usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel__bindgen_ty_1),
+ "::",
+ stringify!(a)
+ )
+ );
}
impl Clone for pixel__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_pixel() {
- assert_eq!(::std::mem::size_of::<pixel>() , 4usize , concat ! (
- "Size of: " , stringify ! ( pixel ) ));
- assert_eq! (::std::mem::align_of::<pixel>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( pixel ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const pixel ) ) . rgba as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( pixel ) , "::" ,
- stringify ! ( rgba ) ));
+ assert_eq!(
+ ::std::mem::size_of::<pixel>(),
+ 4usize,
+ concat!("Size of: ", stringify!(pixel))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<pixel>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(pixel))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const pixel)).rgba as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(pixel),
+ "::",
+ stringify!(rgba)
+ )
+ );
}
impl Clone for pixel {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs
index 4e0f4a18..ba0cf84e 100644
--- a/tests/expectations/tests/union_with_anon_unnamed_union.rs
+++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs
@@ -5,14 +5,14 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo {
pub a: ::std::os::raw::c_uint,
pub __bindgen_anon_1: foo__bindgen_ty_1,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1 {
pub b: ::std::os::raw::c_ushort,
pub c: ::std::os::raw::c_uchar,
@@ -20,42 +20,62 @@ pub union foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 2usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . c as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( c ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 2usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).c as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(c)
+ )
+ );
}
impl Default for foo__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs
index a33c1ccd..d746d45d 100644
--- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs
+++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -51,36 +63,62 @@ pub struct foo__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 2usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . c as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) ,
- "::" , stringify ! ( c ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 2usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(b)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1)).c as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1),
+ "::",
+ stringify!(c)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs
index 9e86f429..e0767ba2 100644
--- a/tests/expectations/tests/union_with_big_member.rs
+++ b/tests/expectations/tests/union_with_big_member.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union WithBigArray {
pub a: ::std::os::raw::c_int,
pub b: [::std::os::raw::c_int; 33usize],
@@ -13,29 +13,44 @@ pub union WithBigArray {
}
#[test]
fn bindgen_test_layout_WithBigArray() {
- assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize , concat ! (
- "Size of: " , stringify ! ( WithBigArray ) ));
- assert_eq! (::std::mem::align_of::<WithBigArray>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
- stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
- stringify ! ( b ) ));
-}
-impl Clone for WithBigArray {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<WithBigArray>(),
+ 132usize,
+ concat!("Size of: ", stringify!(WithBigArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for WithBigArray {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union WithBigArray2 {
pub a: ::std::os::raw::c_int,
pub b: [::std::os::raw::c_char; 33usize],
@@ -43,29 +58,44 @@ pub union WithBigArray2 {
}
#[test]
fn bindgen_test_layout_WithBigArray2() {
- assert_eq!(::std::mem::size_of::<WithBigArray2>() , 36usize , concat ! (
- "Size of: " , stringify ! ( WithBigArray2 ) ));
- assert_eq! (::std::mem::align_of::<WithBigArray2>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigArray2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray2 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::"
- , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray2 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::"
- , stringify ! ( b ) ));
-}
-impl Clone for WithBigArray2 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<WithBigArray2>(),
+ 36usize,
+ concat!("Size of: ", stringify!(WithBigArray2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigArray2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigArray2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray2)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray2),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray2)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray2),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for WithBigArray2 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union WithBigMember {
pub a: ::std::os::raw::c_int,
pub b: WithBigArray,
@@ -73,24 +103,39 @@ pub union WithBigMember {
}
#[test]
fn bindgen_test_layout_WithBigMember() {
- assert_eq!(::std::mem::size_of::<WithBigMember>() , 132usize , concat ! (
- "Size of: " , stringify ! ( WithBigMember ) ));
- assert_eq! (::std::mem::align_of::<WithBigMember>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigMember ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigMember ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigMember ) , "::"
- , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigMember ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigMember ) , "::"
- , stringify ! ( b ) ));
-}
-impl Clone for WithBigMember {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<WithBigMember>(),
+ 132usize,
+ concat!("Size of: ", stringify!(WithBigMember))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigMember>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigMember))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigMember)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigMember),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigMember)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigMember),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Default for WithBigMember {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs
index 03226cce..abf86dc8 100644
--- a/tests/expectations/tests/union_with_big_member_1_0.rs
+++ b/tests/expectations/tests/union_with_big_member_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Copy)]
pub struct WithBigArray {
@@ -44,26 +56,46 @@ pub struct WithBigArray {
}
#[test]
fn bindgen_test_layout_WithBigArray() {
- assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize , concat ! (
- "Size of: " , stringify ! ( WithBigArray ) ));
- assert_eq! (::std::mem::align_of::<WithBigArray>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigArray ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
- stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
- stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WithBigArray>(),
+ 132usize,
+ concat!("Size of: ", stringify!(WithBigArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigArray>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for WithBigArray {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for WithBigArray {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -74,23 +106,41 @@ pub struct WithBigArray2 {
}
#[test]
fn bindgen_test_layout_WithBigArray2() {
- assert_eq!(::std::mem::size_of::<WithBigArray2>() , 36usize , concat ! (
- "Size of: " , stringify ! ( WithBigArray2 ) ));
- assert_eq! (::std::mem::align_of::<WithBigArray2>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigArray2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray2 ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::"
- , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigArray2 ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::"
- , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WithBigArray2>(),
+ 36usize,
+ concat!("Size of: ", stringify!(WithBigArray2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigArray2>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigArray2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray2)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray2),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigArray2)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigArray2),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for WithBigArray2 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Copy)]
@@ -101,24 +151,44 @@ pub struct WithBigMember {
}
#[test]
fn bindgen_test_layout_WithBigMember() {
- assert_eq!(::std::mem::size_of::<WithBigMember>() , 132usize , concat ! (
- "Size of: " , stringify ! ( WithBigMember ) ));
- assert_eq! (::std::mem::align_of::<WithBigMember>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( WithBigMember ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigMember ) ) . a as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigMember ) , "::"
- , stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const WithBigMember ) ) . b as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( WithBigMember ) , "::"
- , stringify ! ( b ) ));
+ assert_eq!(
+ ::std::mem::size_of::<WithBigMember>(),
+ 132usize,
+ concat!("Size of: ", stringify!(WithBigMember))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WithBigMember>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(WithBigMember))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigMember)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigMember),
+ "::",
+ stringify!(a)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WithBigMember)).b as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WithBigMember),
+ "::",
+ stringify!(b)
+ )
+ );
}
impl Clone for WithBigMember {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for WithBigMember {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs
index 7ba8afcb..1969a33c 100644
--- a/tests/expectations/tests/union_with_nesting.rs
+++ b/tests/expectations/tests/union_with_nesting.rs
@@ -5,20 +5,20 @@
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo {
pub a: ::std::os::raw::c_uint,
pub __bindgen_anon_1: foo__bindgen_ty_1,
_bindgen_union_align: u32,
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
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(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1__bindgen_ty_1 {
pub b1: ::std::os::raw::c_ushort,
pub b2: ::std::os::raw::c_ushort,
@@ -26,35 +26,44 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 2usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 2usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b2
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b2 )
- ));
-}
-impl Clone for foo__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).b1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(b1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).b2 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(b2)
+ )
+ );
}
impl Default for foo__bindgen_ty_1__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union foo__bindgen_ty_1__bindgen_ty_2 {
pub c1: ::std::os::raw::c_ushort,
pub c2: ::std::os::raw::c_ushort,
@@ -62,61 +71,80 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 2usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 2usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c2
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c2 )
- ));
-}
-impl Clone for foo__bindgen_ty_1__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 2usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).c1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(c1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).c2 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(c2)
+ )
+ );
}
impl Default for foo__bindgen_ty_1__bindgen_ty_2 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
-}
-impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
}
impl Default for foo__bindgen_ty_1 {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs
index 13870758..1667c07e 100644
--- a/tests/expectations/tests/union_with_nesting_1_0.rs
+++ b/tests/expectations/tests/union_with_nesting_1_0.rs
@@ -6,35 +6,47 @@
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::std::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::std::mem::transmute(self)
+ }
}
-impl <T> ::std::default::Default for __BindgenUnionField<T> {
+impl<T> ::std::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::std::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::std::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::std::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::std::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -57,29 +69,41 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 2usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() ,
- 2usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b2
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b2 )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).b1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(b1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_1)).b2 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_1),
+ "::",
+ stringify!(b2)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -90,52 +114,80 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 {
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 2usize , concat ! (
- "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 )
- ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() ,
- 2usize , concat ! (
- "Alignment of " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c1
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c1 )
- ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c2
- as * const _ as usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! (
- foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c2 )
- ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 2usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).c1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(c1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo__bindgen_ty_1__bindgen_ty_2)).c2 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo__bindgen_ty_1__bindgen_ty_2),
+ "::",
+ stringify!(c2)
+ )
+ );
}
impl Clone for foo__bindgen_ty_1__bindgen_ty_2 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo__bindgen_ty_1() {
- assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat !
- ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) ));
- assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize , concat
- ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo__bindgen_ty_1>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo__bindgen_ty_1))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo__bindgen_ty_1>(),
+ 2usize,
+ concat!("Alignment of ", stringify!(foo__bindgen_ty_1))
+ );
}
impl Clone for foo__bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 4usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs
index dcd1e18e..b5d83c2e 100644
--- a/tests/expectations/tests/unknown_attr.rs
+++ b/tests/expectations/tests/unknown_attr.rs
@@ -5,7 +5,7 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct max_align_t {
pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
pub __bindgen_padding_0: u64,
@@ -14,21 +14,29 @@ pub struct max_align_t {
}
#[test]
fn bindgen_test_layout_max_align_t() {
- assert_eq!(::std::mem::size_of::<max_align_t>() , 32usize , concat ! (
- "Size of: " , stringify ! ( max_align_t ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const max_align_t ) ) .
- __clang_max_align_nonce1 as * const _ as usize } , 0usize ,
- concat ! (
- "Alignment of field: " , stringify ! ( max_align_t ) , "::" ,
- stringify ! ( __clang_max_align_nonce1 ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const max_align_t ) ) .
- __clang_max_align_nonce2 as * const _ as usize } , 16usize ,
- concat ! (
- "Alignment of field: " , stringify ! ( max_align_t ) , "::" ,
- stringify ! ( __clang_max_align_nonce2 ) ));
-}
-impl Clone for max_align_t {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<max_align_t>(),
+ 32usize,
+ concat!("Size of: ", stringify!(max_align_t))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(max_align_t),
+ "::",
+ stringify!(__clang_max_align_nonce1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const max_align_t)).__clang_max_align_nonce2 as *const _ as usize },
+ 16usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(max_align_t),
+ "::",
+ stringify!(__clang_max_align_nonce2)
+ )
+ );
}
diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs
index 6fe4a0ca..ebbfb935 100644
--- a/tests/expectations/tests/use-core.rs
+++ b/tests/expectations/tests/use-core.rs
@@ -6,7 +6,7 @@
extern crate core;
#[repr(C)]
-#[derive(Debug, Copy, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct foo {
pub a: ::std::os::raw::c_int,
pub b: ::std::os::raw::c_int,
@@ -14,34 +14,44 @@ pub struct foo {
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::core::mem::size_of::<foo>() , 16usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::core::mem::align_of::<foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . b as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::core::mem::size_of::<foo>(),
+ 16usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::core::mem::align_of::<foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).b as *const _ as usize },
+ 4usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Default for foo {
- fn default() -> Self { unsafe { ::core::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::core::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Copy)]
+#[derive(Copy, Clone)]
pub union _bindgen_ty_1 {
pub bar: ::std::os::raw::c_int,
pub baz: ::std::os::raw::c_long,
@@ -49,30 +59,44 @@ pub union _bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout__bindgen_ty_1() {
- 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 {
- & ( * ( 0 as * const _bindgen_ty_1 ) ) . bar as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
- , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const _bindgen_ty_1 ) ) . baz as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
- , stringify ! ( baz ) ));
-}
-impl Clone for _bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ 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 { &(*(0 as *const _bindgen_ty_1)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(_bindgen_ty_1),
+ "::",
+ stringify!(bar)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const _bindgen_ty_1)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(_bindgen_ty_1),
+ "::",
+ stringify!(baz)
+ )
+ );
}
impl Default for _bindgen_ty_1 {
- fn default() -> Self { unsafe { ::core::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::core::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "bazz"]
+ #[link_name = "\u{1}bazz"]
pub static mut bazz: _bindgen_ty_1;
}
-pub type fooFunction =
- ::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
+pub type fooFunction = ::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs
index 1e5ef337..4342d606 100644
--- a/tests/expectations/tests/use-core_1_0.rs
+++ b/tests/expectations/tests/use-core_1_0.rs
@@ -7,35 +7,47 @@ extern crate core;
#[repr(C)]
pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>);
-impl <T> __BindgenUnionField<T> {
+impl<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self { __BindgenUnionField(::core::marker::PhantomData) }
+ pub fn new() -> Self {
+ __BindgenUnionField(::core::marker::PhantomData)
+ }
#[inline]
- pub unsafe fn as_ref(&self) -> &T { ::core::mem::transmute(self) }
+ 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) }
+ pub unsafe fn as_mut(&mut self) -> &mut T {
+ ::core::mem::transmute(self)
+ }
}
-impl <T> ::core::default::Default for __BindgenUnionField<T> {
+impl<T> ::core::default::Default for __BindgenUnionField<T> {
#[inline]
- fn default() -> Self { Self::new() }
+ fn default() -> Self {
+ Self::new()
+ }
}
-impl <T> ::core::clone::Clone for __BindgenUnionField<T> {
+impl<T> ::core::clone::Clone for __BindgenUnionField<T> {
#[inline]
- fn clone(&self) -> Self { Self::new() }
+ fn clone(&self) -> Self {
+ Self::new()
+ }
}
-impl <T> ::core::marker::Copy for __BindgenUnionField<T> { }
-impl <T> ::core::fmt::Debug for __BindgenUnionField<T> {
+impl<T> ::core::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::core::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
-impl <T> ::core::hash::Hash for __BindgenUnionField<T> {
- fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) { }
+impl<T> ::core::hash::Hash for __BindgenUnionField<T> {
+ fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {}
}
-impl <T> ::core::cmp::PartialEq for __BindgenUnionField<T> {
- fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { true }
+impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> {
+ fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+ true
+ }
}
-impl <T> ::core::cmp::Eq for __BindgenUnionField<T> { }
+impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {}
#[repr(C)]
#[derive(Debug, Copy, Hash, PartialEq, Eq)]
pub struct foo {
@@ -45,31 +57,46 @@ pub struct foo {
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::core::mem::size_of::<foo>() , 16usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::core::mem::align_of::<foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . a as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( a ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . b as * const _ as usize } ,
- 4usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( b ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( bar ) ));
+ assert_eq!(
+ ::core::mem::size_of::<foo>(),
+ 16usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::core::mem::align_of::<foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).a as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(a))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).b as *const _ as usize },
+ 4usize,
+ concat!("Alignment of field: ", stringify!(foo), "::", stringify!(b))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).bar as *const _ as usize },
+ 8usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(bar)
+ )
+ );
}
impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
impl Default for foo {
- fn default() -> Self { unsafe { ::core::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::core::mem::zeroed() }
+ }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
@@ -80,27 +107,44 @@ pub struct _bindgen_ty_1 {
}
#[test]
fn bindgen_test_layout__bindgen_ty_1() {
- 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 {
- & ( * ( 0 as * const _bindgen_ty_1 ) ) . bar as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
- , stringify ! ( bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const _bindgen_ty_1 ) ) . baz as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
- , stringify ! ( baz ) ));
+ 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 { &(*(0 as *const _bindgen_ty_1)).bar as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(_bindgen_ty_1),
+ "::",
+ stringify!(bar)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const _bindgen_ty_1)).baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(_bindgen_ty_1),
+ "::",
+ stringify!(baz)
+ )
+ );
}
impl Clone for _bindgen_ty_1 {
- fn clone(&self) -> Self { *self }
+ fn clone(&self) -> Self {
+ *self
+ }
}
extern "C" {
- #[link_name = "bazz"]
+ #[link_name = "\u{1}bazz"]
pub static mut bazz: _bindgen_ty_1;
}
-pub type fooFunction =
- ::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
+pub type fooFunction = ::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
diff --git a/tests/expectations/tests/using.rs b/tests/expectations/tests/using.rs
index 0dc1ec21..9bc5e303 100644
--- a/tests/expectations/tests/using.rs
+++ b/tests/expectations/tests/using.rs
@@ -11,8 +11,10 @@ pub struct Point<T> {
pub y: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for Point<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for Point<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub type IntPoint2D = Point<::std::os::raw::c_int>;
pub type IntVec2D = Point<::std::os::raw::c_int>;
diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs
index 3eb93b04..d99526c7 100644
--- a/tests/expectations/tests/var-tracing.rs
+++ b/tests/expectations/tests/var-tracing.rs
@@ -5,29 +5,37 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub m_baz: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Bar ) ) . m_baz as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Bar ) , "::" ,
- stringify ! ( m_baz ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 4usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Bar)).m_baz as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Bar),
+ "::",
+ stringify!(m_baz)
+ )
+ );
}
extern "C" {
- #[link_name = "_ZN3BarC1Ei"]
+ #[link_name = "\u{1}_ZN3BarC1Ei"]
pub fn Bar_Bar(this: *mut Bar, baz: ::std::os::raw::c_int);
}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
-}
impl Bar {
#[inline]
pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self {
@@ -37,21 +45,24 @@ impl Bar {
}
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Baz {
pub _address: u8,
}
extern "C" {
- #[link_name = "_ZN3Baz3FOOE"]
+ #[link_name = "\u{1}_ZN3Baz3FOOE"]
pub static mut Baz_FOO: [Bar; 0usize];
}
#[test]
fn bindgen_test_layout_Baz() {
- assert_eq!(::std::mem::size_of::<Baz>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Baz ) ));
- assert_eq! (::std::mem::align_of::<Baz>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Baz ) ));
-}
-impl Clone for Baz {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Baz>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Baz))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Baz>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Baz))
+ );
}
diff --git a/tests/expectations/tests/variadic-method.rs b/tests/expectations/tests/variadic-method.rs
index a68dd1c9..94dd73be 100644
--- a/tests/expectations/tests/variadic-method.rs
+++ b/tests/expectations/tests/variadic-method.rs
@@ -5,25 +5,28 @@
extern "C" {
- #[link_name = "_Z3fooPKcz"]
+ #[link_name = "\u{1}_Z3fooPKcz"]
pub fn foo(fmt: *const ::std::os::raw::c_char, ...);
}
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Bar() {
- assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Bar ) ));
- assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Bar ) ));
+ assert_eq!(
+ ::std::mem::size_of::<Bar>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Bar))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Bar>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Bar))
+ );
}
extern "C" {
- #[link_name = "_ZN3Bar3fooEPKcz"]
+ #[link_name = "\u{1}_ZN3Bar3fooEPKcz"]
pub fn Bar_foo(this: *mut Bar, fmt: *const ::std::os::raw::c_char, ...);
}
-impl Clone for Bar {
- fn clone(&self) -> Self { *self }
-}
diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs
index a4b87c7f..c75e9829 100644
--- a/tests/expectations/tests/vector.rs
+++ b/tests/expectations/tests/vector.rs
@@ -5,22 +5,30 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct foo {
pub mMember: [::std::os::raw::c_longlong; 1usize],
}
#[test]
fn bindgen_test_layout_foo() {
- assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! (
- "Size of: " , stringify ! ( foo ) ));
- assert_eq! (::std::mem::align_of::<foo>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( foo ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const foo ) ) . mMember as * const _ as usize }
- , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( foo ) , "::" ,
- stringify ! ( mMember ) ));
-}
-impl Clone for foo {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 8usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const foo)).mMember as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(mMember)
+ )
+ );
}
diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs
index 8d6d9dcd..72086053 100644
--- a/tests/expectations/tests/virtual_dtor.rs
+++ b/tests/expectations/tests/virtual_dtor.rs
@@ -13,15 +13,23 @@ pub struct nsSlots {
}
#[test]
fn bindgen_test_layout_nsSlots() {
- assert_eq!(::std::mem::size_of::<nsSlots>() , 8usize , concat ! (
- "Size of: " , stringify ! ( nsSlots ) ));
- assert_eq! (::std::mem::align_of::<nsSlots>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( nsSlots ) ));
+ assert_eq!(
+ ::std::mem::size_of::<nsSlots>(),
+ 8usize,
+ concat!("Size of: ", stringify!(nsSlots))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<nsSlots>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(nsSlots))
+ );
}
impl Default for nsSlots {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_ZN7nsSlotsD0Ev"]
+ #[link_name = "\u{1}_ZN7nsSlotsD0Ev"]
pub fn nsSlots_nsSlots_destructor(this: *mut nsSlots);
}
diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs
index e177dca8..c4f7abfa 100644
--- a/tests/expectations/tests/virtual_inheritance.rs
+++ b/tests/expectations/tests/virtual_inheritance.rs
@@ -5,79 +5,92 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct A {
pub foo: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_A() {
- assert_eq!(::std::mem::size_of::<A>() , 4usize , concat ! (
- "Size of: " , stringify ! ( A ) ));
- assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! (
- "Alignment of " , stringify ! ( A ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const A ) ) . foo as * const _ as usize } ,
- 0usize , concat ! (
- "Alignment of field: " , stringify ! ( A ) , "::" , stringify
- ! ( foo ) ));
-}
-impl Clone for A {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<A>(),
+ 4usize,
+ concat!("Size of: ", stringify!(A))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<A>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(A))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const A)).foo as *const _ as usize },
+ 0usize,
+ concat!("Alignment of field: ", stringify!(A), "::", stringify!(foo))
+ );
}
#[repr(C)]
pub struct B__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct B {
pub vtable_: *const B__bindgen_vtable,
pub bar: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_B() {
- assert_eq!(::std::mem::size_of::<B>() , 16usize , concat ! (
- "Size of: " , stringify ! ( B ) ));
- assert_eq! (::std::mem::align_of::<B>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( B ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const B ) ) . bar as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( B ) , "::" , stringify
- ! ( bar ) ));
-}
-impl Clone for B {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<B>(),
+ 16usize,
+ concat!("Size of: ", stringify!(B))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<B>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(B))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const B)).bar as *const _ as usize },
+ 8usize,
+ concat!("Alignment of field: ", stringify!(B), "::", stringify!(bar))
+ );
}
impl Default for B {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
pub struct C__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct C {
pub vtable_: *const C__bindgen_vtable,
pub baz: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 16usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const C ) ) . baz as * const _ as usize } ,
- 8usize , concat ! (
- "Alignment of field: " , stringify ! ( C ) , "::" , stringify
- ! ( baz ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 16usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(C))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const C)).baz as *const _ as usize },
+ 8usize,
+ concat!("Alignment of field: ", stringify!(C), "::", stringify!(baz))
+ );
}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct D {
pub _base: C,
pub _base_1: B,
@@ -85,14 +98,19 @@ pub struct D {
}
#[test]
fn bindgen_test_layout_D() {
- assert_eq!(::std::mem::size_of::<D>() , 40usize , concat ! (
- "Size of: " , stringify ! ( D ) ));
- assert_eq! (::std::mem::align_of::<D>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( D ) ));
-}
-impl Clone for D {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<D>(),
+ 40usize,
+ concat!("Size of: ", stringify!(D))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<D>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(D))
+ );
}
impl Default for D {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs
index 90f9d928..376bae8a 100644
--- a/tests/expectations/tests/virtual_overloaded.rs
+++ b/tests/expectations/tests/virtual_overloaded.rs
@@ -7,30 +7,33 @@
#[repr(C)]
pub struct C__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct C {
pub vtable_: *const C__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_C() {
- assert_eq!(::std::mem::size_of::<C>() , 8usize , concat ! (
- "Size of: " , stringify ! ( C ) ));
- assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( C ) ));
-}
-impl Clone for C {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<C>(),
+ 8usize,
+ concat!("Size of: ", stringify!(C))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<C>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(C))
+ );
}
impl Default for C {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_ZN1C8do_thingEc"]
- pub fn C_do_thing(this: *mut ::std::os::raw::c_void,
- arg1: ::std::os::raw::c_char);
+ #[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" {
- #[link_name = "_ZN1C8do_thingEi"]
- pub fn C_do_thing1(this: *mut ::std::os::raw::c_void,
- arg1: ::std::os::raw::c_int);
+ #[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/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs
index ab2cd875..f0720f27 100644
--- a/tests/expectations/tests/vtable_recursive_sig.rs
+++ b/tests/expectations/tests/vtable_recursive_sig.rs
@@ -7,42 +7,52 @@
#[repr(C)]
pub struct Base__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Base {
pub vtable_: *const Base__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_Base() {
- assert_eq!(::std::mem::size_of::<Base>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Base ) ));
- assert_eq! (::std::mem::align_of::<Base>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Base ) ));
-}
-impl Clone for Base {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Base>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Base))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Base>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Base))
+ );
}
impl Default for Base {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
extern "C" {
- #[link_name = "_ZN4Base9AsDerivedEv"]
+ #[link_name = "\u{1}_ZN4Base9AsDerivedEv"]
pub fn Base_AsDerived(this: *mut ::std::os::raw::c_void) -> *mut Derived;
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Derived {
pub _base: Base,
}
#[test]
fn bindgen_test_layout_Derived() {
- assert_eq!(::std::mem::size_of::<Derived>() , 8usize , concat ! (
- "Size of: " , stringify ! ( Derived ) ));
- assert_eq! (::std::mem::align_of::<Derived>() , 8usize , concat ! (
- "Alignment of " , stringify ! ( Derived ) ));
-}
-impl Clone for Derived {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Derived>(),
+ 8usize,
+ concat!("Size of: ", stringify!(Derived))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Derived>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(Derived))
+ );
}
impl Default for Derived {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs
index 06f3af34..ac73b709 100644
--- a/tests/expectations/tests/weird_bitfields.rs
+++ b/tests/expectations/tests/weird_bitfields.rs
@@ -12,7 +12,7 @@ pub enum nsStyleSVGOpacitySource {
eStyleSVGOpacitySource_ContextStrokeOpacity = 2,
}
#[repr(C)]
-#[derive(Debug, Copy)]
+#[derive(Debug, Copy, Clone)]
pub struct Weird {
pub mStrokeDasharrayLength: ::std::os::raw::c_uint,
pub _bitfield_1: [u16; 2usize],
@@ -163,11 +163,6 @@ fn bindgen_test_layout_Weird() {
)
);
}
-impl Clone for Weird {
- fn clone(&self) -> Self {
- *self
- }
-}
impl Default for Weird {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
@@ -184,13 +179,13 @@ impl Weird {
::std::mem::size_of::<u32>(),
)
};
- let mask = 65535u64 as u32;
+ let mask = 0xffff as u32;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_bitTest(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 65535u64 as u32;
+ let mask = 0xffff as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -220,13 +215,13 @@ impl Weird {
::std::mem::size_of::<u32>(),
)
};
- let mask = 2147418112u64 as u32;
+ let mask = 0x7fff0000 as u32;
let val = (unit_field_val & mask) >> 16usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_bitTest2(&mut self, val: ::std::os::raw::c_uint) {
- let mask = 2147418112u64 as u32;
+ let mask = 0x7fff0000 as u32;
let val = val as u32 as u32;
let mut unit_field_val: u32 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -251,8 +246,8 @@ impl Weird {
bitTest: ::std::os::raw::c_uint,
bitTest2: ::std::os::raw::c_uint,
) -> u32 {
- ((0 | ((bitTest as u32 as u32) << 0usize) & (65535u64 as u32)) |
- ((bitTest2 as u32 as u32) << 16usize) & (2147418112u64 as u32))
+ ((0 | ((bitTest as u32 as u32) << 0usize) & (0xffff as u32))
+ | ((bitTest2 as u32 as u32) << 16usize) & (0x7fff0000 as u32))
}
#[inline]
pub fn mFillOpacitySource(&self) -> nsStyleSVGOpacitySource {
@@ -264,13 +259,13 @@ impl Weird {
::std::mem::size_of::<u16>(),
)
};
- let mask = 7u64 as u16;
+ let mask = 0x7 as u16;
let val = (unit_field_val & mask) >> 0usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_mFillOpacitySource(&mut self, val: nsStyleSVGOpacitySource) {
- let mask = 7u64 as u16;
+ let mask = 0x7 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -300,13 +295,13 @@ impl Weird {
::std::mem::size_of::<u16>(),
)
};
- let mask = 56u64 as u16;
+ let mask = 0x38 as u16;
let val = (unit_field_val & mask) >> 3usize;
unsafe { ::std::mem::transmute(val as u32) }
}
#[inline]
pub fn set_mStrokeOpacitySource(&mut self, val: nsStyleSVGOpacitySource) {
- let mask = 56u64 as u16;
+ let mask = 0x38 as u16;
let val = val as u32 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -336,13 +331,13 @@ impl Weird {
::std::mem::size_of::<u16>(),
)
};
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = (unit_field_val & mask) >> 6usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_mStrokeDasharrayFromObject(&mut self, val: bool) {
- let mask = 64u64 as u16;
+ let mask = 0x40 as u16;
let val = val as u8 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -372,13 +367,13 @@ impl Weird {
::std::mem::size_of::<u16>(),
)
};
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = (unit_field_val & mask) >> 7usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_mStrokeDashoffsetFromObject(&mut self, val: bool) {
- let mask = 128u64 as u16;
+ let mask = 0x80 as u16;
let val = val as u8 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -408,13 +403,13 @@ impl Weird {
::std::mem::size_of::<u16>(),
)
};
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = (unit_field_val & mask) >> 8usize;
unsafe { ::std::mem::transmute(val as u8) }
}
#[inline]
pub fn set_mStrokeWidthFromObject(&mut self, val: bool) {
- let mask = 256u64 as u16;
+ let mask = 0x100 as u16;
let val = val as u8 as u16;
let mut unit_field_val: u16 = unsafe { ::std::mem::uninitialized() };
unsafe {
@@ -442,10 +437,10 @@ impl Weird {
mStrokeDashoffsetFromObject: bool,
mStrokeWidthFromObject: bool,
) -> u16 {
- (((((0 | ((mFillOpacitySource as u32 as u16) << 0usize) & (7u64 as u16)) |
- ((mStrokeOpacitySource as u32 as u16) << 3usize) & (56u64 as u16)) |
- ((mStrokeDasharrayFromObject as u8 as u16) << 6usize) & (64u64 as u16)) |
- ((mStrokeDashoffsetFromObject as u8 as u16) << 7usize) & (128u64 as u16)) |
- ((mStrokeWidthFromObject as u8 as u16) << 8usize) & (256u64 as u16))
+ (((((0 | ((mFillOpacitySource as u32 as u16) << 0usize) & (0x7 as u16))
+ | ((mStrokeOpacitySource as u32 as u16) << 3usize) & (0x38 as u16))
+ | ((mStrokeDasharrayFromObject as u8 as u16) << 6usize) & (0x40 as u16))
+ | ((mStrokeDashoffsetFromObject as u8 as u16) << 7usize) & (0x80 as u16))
+ | ((mStrokeWidthFromObject as u8 as u16) << 8usize) & (0x100 as u16))
}
}
diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs
index daa6407b..d0e4c689 100644
--- a/tests/expectations/tests/what_is_going_on.rs
+++ b/tests/expectations/tests/what_is_going_on.rs
@@ -5,19 +5,22 @@
#[repr(C)]
-#[derive(Debug, Default, Copy)]
+#[derive(Debug, Default, Copy, Clone)]
pub struct UnknownUnits {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_UnknownUnits() {
- assert_eq!(::std::mem::size_of::<UnknownUnits>() , 1usize , concat ! (
- "Size of: " , stringify ! ( UnknownUnits ) ));
- assert_eq! (::std::mem::align_of::<UnknownUnits>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( UnknownUnits ) ));
-}
-impl Clone for UnknownUnits {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<UnknownUnits>(),
+ 1usize,
+ concat!("Size of: ", stringify!(UnknownUnits))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<UnknownUnits>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(UnknownUnits))
+ );
}
pub type Float = f32;
#[repr(C)]
@@ -27,7 +30,9 @@ pub struct PointTyped<F> {
pub y: F,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<F>>,
}
-impl <F> Default for PointTyped<F> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<F> Default for PointTyped<F> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
pub type IntPoint = PointTyped<f32>;
diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs
index bdb35589..74c782f7 100644
--- a/tests/expectations/tests/whitelist-namespaces-basic.rs
+++ b/tests/expectations/tests/whitelist-namespaces-basic.rs
@@ -15,19 +15,22 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Helper {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Helper() {
- assert_eq!(::std::mem::size_of::<Helper>() , 1usize , concat !
- ( "Size of: " , stringify ! ( Helper ) ));
- assert_eq! (::std::mem::align_of::<Helper>() , 1usize , concat
- ! ( "Alignment of " , stringify ! ( Helper ) ));
- }
- impl Clone for Helper {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Helper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Helper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Helper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Helper))
+ );
}
}
}
diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/whitelist-namespaces.rs
index e19bdba3..f1c86bde 100644
--- a/tests/expectations/tests/whitelist-namespaces.rs
+++ b/tests/expectations/tests/whitelist-namespaces.rs
@@ -15,40 +15,51 @@ pub mod root {
#[allow(unused_imports)]
use self::super::super::super::root;
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Helper {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Helper() {
- assert_eq!(::std::mem::size_of::<Helper>() , 1usize , concat !
- ( "Size of: " , stringify ! ( Helper ) ));
- assert_eq! (::std::mem::align_of::<Helper>() , 1usize , concat
- ! ( "Alignment of " , stringify ! ( Helper ) ));
- }
- impl Clone for Helper {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Helper>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Helper))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Helper>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Helper))
+ );
}
}
#[repr(C)]
- #[derive(Debug, Default, Copy)]
+ #[derive(Debug, Default, Copy, Clone)]
pub struct Test {
pub helper: root::outer::inner::Helper,
}
#[test]
fn bindgen_test_layout_Test() {
- assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! (
- "Size of: " , stringify ! ( Test ) ));
- assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! (
- "Alignment of " , stringify ! ( Test ) ));
- assert_eq! (unsafe {
- & ( * ( 0 as * const Test ) ) . helper as * const _ as
- usize } , 0usize , concat ! (
- "Alignment of field: " , stringify ! ( Test ) , "::" ,
- stringify ! ( helper ) ));
- }
- impl Clone for Test {
- fn clone(&self) -> Self { *self }
+ assert_eq!(
+ ::std::mem::size_of::<Test>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Test))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Test>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Test))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Test)).helper as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Test),
+ "::",
+ stringify!(helper)
+ )
+ );
}
}
}
diff --git a/tests/expectations/tests/whitelist_basic.rs b/tests/expectations/tests/whitelist_basic.rs
index af151e3e..7ff1160d 100644
--- a/tests/expectations/tests/whitelist_basic.rs
+++ b/tests/expectations/tests/whitelist_basic.rs
@@ -17,9 +17,13 @@ pub struct WhitelistMe_Inner<T> {
pub bar: T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-impl <T> Default for WhitelistMe_Inner<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for WhitelistMe_Inner<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
-impl <T> Default for WhitelistMe<T> {
- fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+impl<T> Default for WhitelistMe<T> {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
}
diff --git a/tests/expectations/tests/whitelisted-item-references-no-hash.rs b/tests/expectations/tests/whitelisted-item-references-no-hash.rs
new file mode 100644
index 00000000..5a77ff75
--- /dev/null
+++ b/tests/expectations/tests/whitelisted-item-references-no-hash.rs
@@ -0,0 +1,52 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct NoHash {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_NoHash() {
+ assert_eq!(
+ ::std::mem::size_of::<NoHash>(),
+ 1usize,
+ concat!("Size of: ", stringify!(NoHash))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoHash>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(NoHash))
+ );
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct WhitelistMe {
+ pub a: NoHash,
+}
+#[test]
+fn bindgen_test_layout_WhitelistMe() {
+ assert_eq!(
+ ::std::mem::size_of::<WhitelistMe>(),
+ 1usize,
+ concat!("Size of: ", stringify!(WhitelistMe))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WhitelistMe>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(WhitelistMe))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WhitelistMe)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WhitelistMe),
+ "::",
+ stringify!(a)
+ )
+ );
+}
diff --git a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs b/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs
new file mode 100644
index 00000000..32604b12
--- /dev/null
+++ b/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs
@@ -0,0 +1,52 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct NoPartialEq {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_NoPartialEq() {
+ assert_eq!(
+ ::std::mem::size_of::<NoPartialEq>(),
+ 1usize,
+ concat!("Size of: ", stringify!(NoPartialEq))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoPartialEq>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(NoPartialEq))
+ );
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct WhitelistMe {
+ pub a: NoPartialEq,
+}
+#[test]
+fn bindgen_test_layout_WhitelistMe() {
+ assert_eq!(
+ ::std::mem::size_of::<WhitelistMe>(),
+ 1usize,
+ concat!("Size of: ", stringify!(WhitelistMe))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WhitelistMe>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(WhitelistMe))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WhitelistMe)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WhitelistMe),
+ "::",
+ stringify!(a)
+ )
+ );
+}
diff --git a/tests/expectations/tests/whitelisted_item_references_no_copy.rs b/tests/expectations/tests/whitelisted_item_references_no_copy.rs
new file mode 100644
index 00000000..91b6d46a
--- /dev/null
+++ b/tests/expectations/tests/whitelisted_item_references_no_copy.rs
@@ -0,0 +1,52 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct NoCopy {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_NoCopy() {
+ assert_eq!(
+ ::std::mem::size_of::<NoCopy>(),
+ 1usize,
+ concat!("Size of: ", stringify!(NoCopy))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<NoCopy>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(NoCopy))
+ );
+}
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct WhitelistMe {
+ pub a: NoCopy,
+}
+#[test]
+fn bindgen_test_layout_WhitelistMe() {
+ assert_eq!(
+ ::std::mem::size_of::<WhitelistMe>(),
+ 1usize,
+ concat!("Size of: ", stringify!(WhitelistMe))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<WhitelistMe>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(WhitelistMe))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const WhitelistMe)).a as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(WhitelistMe),
+ "::",
+ stringify!(a)
+ )
+ );
+}
diff --git a/tests/expectations/tests/win32-thiscall_1_0.rs b/tests/expectations/tests/win32-thiscall_1_0.rs
new file mode 100644
index 00000000..f84a7005
--- /dev/null
+++ b/tests/expectations/tests/win32-thiscall_1_0.rs
@@ -0,0 +1,29 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
diff --git a/tests/expectations/tests/win32-thiscall_nightly.rs b/tests/expectations/tests/win32-thiscall_nightly.rs
new file mode 100644
index 00000000..3b0140dc
--- /dev/null
+++ b/tests/expectations/tests/win32-thiscall_nightly.rs
@@ -0,0 +1,43 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![cfg(feature = "nightly")]
+#![feature(abi_thiscall)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Foo {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 1usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+}
+extern "thiscall" {
+ #[link_name = "\u{1}?test@Foo@@QAEXXZ"]
+ pub fn Foo_test(this: *mut Foo);
+}
+extern "thiscall" {
+ #[link_name = "\u{1}?test2@Foo@@QAEHH@Z"]
+ pub fn Foo_test2(this: *mut Foo, var: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
+}
+impl Foo {
+ #[inline]
+ pub unsafe fn test(&mut self) {
+ Foo_test(self)
+ }
+ #[inline]
+ pub unsafe fn test2(&mut self, var: ::std::os::raw::c_int) -> ::std::os::raw::c_int {
+ Foo_test2(self, var)
+ }
+}
diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs
new file mode 100644
index 00000000..15e5bc1f
--- /dev/null
+++ b/tests/expectations/tests/zero-sized-array.rs
@@ -0,0 +1,159 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Default)]
+pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
+impl<T> __IncompleteArrayField<T> {
+ #[inline]
+ pub fn new() -> Self {
+ __IncompleteArrayField(::std::marker::PhantomData)
+ }
+ #[inline]
+ pub unsafe fn as_ptr(&self) -> *const T {
+ ::std::mem::transmute(self)
+ }
+ #[inline]
+ pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
+ ::std::mem::transmute(self)
+ }
+ #[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<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
+ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ fmt.write_str("__IncompleteArrayField")
+ }
+}
+impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
+ #[inline]
+ fn clone(&self) -> Self {
+ Self::new()
+ }
+}
+impl<T> ::std::marker::Copy for __IncompleteArrayField<T> {}
+/// Bizarrely enough, this should *not* get an `_address` field.
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct ZeroSizedArray {
+ pub arr: __IncompleteArrayField<::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_ZeroSizedArray() {
+ assert_eq!(
+ ::std::mem::size_of::<ZeroSizedArray>(),
+ 0usize,
+ concat!("Size of: ", stringify!(ZeroSizedArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ZeroSizedArray>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(ZeroSizedArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ZeroSizedArray)).arr as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ZeroSizedArray),
+ "::",
+ stringify!(arr)
+ )
+ );
+}
+/// And nor should this get an `_address` field.
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct ContainsZeroSizedArray {
+ pub zsa: ZeroSizedArray,
+}
+#[test]
+fn bindgen_test_layout_ContainsZeroSizedArray() {
+ assert_eq!(
+ ::std::mem::size_of::<ContainsZeroSizedArray>(),
+ 0usize,
+ concat!("Size of: ", stringify!(ContainsZeroSizedArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ContainsZeroSizedArray>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(ContainsZeroSizedArray))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const ContainsZeroSizedArray)).zsa as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(ContainsZeroSizedArray),
+ "::",
+ stringify!(zsa)
+ )
+ );
+}
+/// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted
+/// either.
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct InheritsZeroSizedArray {
+ pub _base: ZeroSizedArray,
+}
+#[test]
+fn bindgen_test_layout_InheritsZeroSizedArray() {
+ assert_eq!(
+ ::std::mem::size_of::<InheritsZeroSizedArray>(),
+ 0usize,
+ concat!("Size of: ", stringify!(InheritsZeroSizedArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<InheritsZeroSizedArray>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(InheritsZeroSizedArray))
+ );
+}
+/// And this should not get an `_address` field either.
+#[repr(C, packed)]
+#[derive(Debug, Default)]
+pub struct DynamicallySizedArray {
+ pub arr: __IncompleteArrayField<::std::os::raw::c_char>,
+}
+#[test]
+fn bindgen_test_layout_DynamicallySizedArray() {
+ assert_eq!(
+ ::std::mem::size_of::<DynamicallySizedArray>(),
+ 0usize,
+ concat!("Size of: ", stringify!(DynamicallySizedArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<DynamicallySizedArray>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(DynamicallySizedArray))
+ );
+}
+/// No `_address` field here either.
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct ContainsDynamicallySizedArray {
+ pub dsa: DynamicallySizedArray,
+}
+#[test]
+fn bindgen_test_layout_ContainsDynamicallySizedArray() {
+ assert_eq!(
+ ::std::mem::size_of::<ContainsDynamicallySizedArray>(),
+ 0usize,
+ concat!("Size of: ", stringify!(ContainsDynamicallySizedArray))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<ContainsDynamicallySizedArray>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray))
+ );
+}
diff --git a/tests/headers/array-of-zero-sized-types.hpp b/tests/headers/array-of-zero-sized-types.hpp
new file mode 100644
index 00000000..87b36d41
--- /dev/null
+++ b/tests/headers/array-of-zero-sized-types.hpp
@@ -0,0 +1,12 @@
+/**
+ * This should get an `_address` byte.
+ */
+struct Empty {};
+
+/**
+ * This should not get an `_address` byte, since each `Empty` gets one, meaning
+ * that this object is addressable.
+ */
+struct HasArrayOfEmpty {
+ Empty empties[10];
+};
diff --git a/tests/headers/bitfield_large_overflow.hpp b/tests/headers/bitfield_large_overflow.hpp
new file mode 100644
index 00000000..9e040ae3
--- /dev/null
+++ b/tests/headers/bitfield_large_overflow.hpp
@@ -0,0 +1,3 @@
+struct {
+ unsigned : 632;
+} a;
diff --git a/tests/headers/call-conv-field.h b/tests/headers/call-conv-field.h
index 00ebd094..6fa5c46f 100644
--- a/tests/headers/call-conv-field.h
+++ b/tests/headers/call-conv-field.h
@@ -1,4 +1,4 @@
-// bindgen-flags: -- -target i686-pc-win32
+// bindgen-flags: -- --target=i686-pc-win32
// bindgen-unstable
// bindgen-generate-bindings-on-linux-only
//
diff --git a/tests/headers/class.hpp b/tests/headers/class.hpp
index ac2da1a4..f77ac92a 100644
--- a/tests/headers/class.hpp
+++ b/tests/headers/class.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --with-derive-partialord --with-derive-ord
//
class C {
int a;
@@ -13,6 +13,11 @@ class C_with_zero_length_array {
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)
@@ -20,6 +25,11 @@ class C_with_incomplete_array {
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)
@@ -28,6 +38,12 @@ class C_with_zero_length_array_and_incomplete_array {
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;
diff --git a/tests/headers/class_1_0.hpp b/tests/headers/class_1_0.hpp
index ee00c2b7..e3735eb6 100644
--- a/tests/headers/class_1_0.hpp
+++ b/tests/headers/class_1_0.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --impl-partialeq --with-derive-eq
class C {
int a;
@@ -13,6 +13,11 @@ class C_with_zero_length_array {
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)
@@ -20,6 +25,12 @@ class C_with_incomplete_array {
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)
@@ -28,6 +39,13 @@ class C_with_zero_length_array_and_incomplete_array {
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;
diff --git a/tests/headers/contains-vs-inherits-zero-sized.hpp b/tests/headers/contains-vs-inherits-zero-sized.hpp
new file mode 100644
index 00000000..d354b0a2
--- /dev/null
+++ b/tests/headers/contains-vs-inherits-zero-sized.hpp
@@ -0,0 +1,21 @@
+/**
+ * This should get an `_address` byte.
+ */
+struct Empty {};
+
+/**
+ * This should not get an `_address` byte, so `sizeof(Inherits)` should be
+ * `1`.
+ */
+struct Inherits : public Empty {
+ bool b;
+};
+
+/**
+ * This should not get an `_address` byte, but contains `Empty` which *does* get
+ * one, so `sizeof(Contains)` should be `1 + 1`.
+ */
+struct Contains {
+ Empty empty;
+ bool b;
+};
diff --git a/tests/headers/derive-bitfield-method-same-name.hpp b/tests/headers/derive-bitfield-method-same-name.hpp
new file mode 100644
index 00000000..4b7b21e9
--- /dev/null
+++ b/tests/headers/derive-bitfield-method-same-name.hpp
@@ -0,0 +1,13 @@
+// bindgen-flags: --with-derive-partialeq --impl-partialeq --impl-debug
+
+/// Because this struct have array larger than 32 items
+/// and --with-derive-partialeq --impl-partialeq --impl-debug is provided,
+/// this struct should manually implement `Debug` and `PartialEq`.
+struct Foo {
+ int large[33];
+ char type_ : 3;
+ unsigned : 8;
+ char type();
+ void set_type_(char c);
+ void set_type(char c);
+};
diff --git a/tests/headers/derive-clone.h b/tests/headers/derive-clone.h
new file mode 100644
index 00000000..a84d35cd
--- /dev/null
+++ b/tests/headers/derive-clone.h
@@ -0,0 +1,5 @@
+
+/// This struct should derive `Clone`.
+struct ShouldDeriveClone {
+ int large[33];
+};
diff --git a/tests/headers/derive-clone_1_0.h b/tests/headers/derive-clone_1_0.h
new file mode 100644
index 00000000..34ef40ae
--- /dev/null
+++ b/tests/headers/derive-clone_1_0.h
@@ -0,0 +1,7 @@
+// 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/tests/headers/derive-hash-blacklisting.hpp b/tests/headers/derive-hash-blacklisting.hpp
index c39c31ad..e3256a01 100644
--- a/tests/headers/derive-hash-blacklisting.hpp
+++ b/tests/headers/derive-hash-blacklisting.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
+// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted<T> {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>> }"
//
template <class T>
struct Blacklisted {
diff --git a/tests/headers/derive-hash-struct-with-anon-struct-float.h b/tests/headers/derive-hash-struct-with-anon-struct-float.h
index 64fe7fd9..dc6e7329 100644
--- a/tests/headers/derive-hash-struct-with-anon-struct-float.h
+++ b/tests/headers/derive-hash-struct-with-anon-struct-float.h
@@ -1,6 +1,6 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq
//
-/// A struct containing a struct containing a float that cannot derive hash/eq but can derive partial eq.
+/// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
struct foo {
struct {
float a;
diff --git a/tests/headers/derive-hash-struct-with-float-array.h b/tests/headers/derive-hash-struct-with-float-array.h
index a34904f7..2294b1de 100644
--- a/tests/headers/derive-hash-struct-with-float-array.h
+++ b/tests/headers/derive-hash-struct-with-float-array.h
@@ -1,6 +1,6 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq
//
-/// A struct containing an array of floats that cannot derive hash/eq but can derive partialeq.
+/// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
struct foo {
float bar[3];
};
diff --git a/tests/headers/derive-hash-struct-with-incomplete-array.h b/tests/headers/derive-hash-struct-with-incomplete-array.h
new file mode 100644
index 00000000..65c009db
--- /dev/null
+++ b/tests/headers/derive-hash-struct-with-incomplete-array.h
@@ -0,0 +1,17 @@
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --with-derive-partialord --with-derive-ord
+//
+struct test {
+ int a;
+ char zero_length_array[0];
+};
+
+struct test2 {
+ int a;
+ char incomplete_array[];
+};
+
+struct test3 {
+ int a;
+ char zero_length_array[0];
+ char incomplete_array[];
+};
diff --git a/tests/headers/derive-hash-struct-with-pointer.h b/tests/headers/derive-hash-struct-with-pointer.h
index d7f18a6d..a3ce9cc5 100644
--- a/tests/headers/derive-hash-struct-with-pointer.h
+++ b/tests/headers/derive-hash-struct-with-pointer.h
@@ -1,6 +1,6 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq
//
-/// Pointers can derive hash/PartialEq/Eq
+/// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq
struct ConstPtrMutObj {
int* const bar;
};
diff --git a/tests/headers/derive-hash-template-def-float.hpp b/tests/headers/derive-hash-template-def-float.hpp
index 8c1a14d1..253fb9ce 100644
--- a/tests/headers/derive-hash-template-def-float.hpp
+++ b/tests/headers/derive-hash-template-def-float.hpp
@@ -1,6 +1,6 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq
//
-/// Template definition containing a float, which cannot derive hash/eq but can derive partialeq.
+/// Template definition containing a float, which cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd.
template <typename T>
struct foo {
T data;
diff --git a/tests/headers/derive-hash-template-inst-float.hpp b/tests/headers/derive-hash-template-inst-float.hpp
index 14fd89a0..0a4fc0c1 100644
--- a/tests/headers/derive-hash-template-inst-float.hpp
+++ b/tests/headers/derive-hash-template-inst-float.hpp
@@ -1,17 +1,17 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq
//
-/// Template definition that doesn't contain float can derive hash/partialeq/eq
+/// Template definition that doesn't contain float can derive Hash/PartialOrd/Ord/PartialEq/Eq
template <typename T>
struct foo {
T data;
};
-/// Can derive hash/partialeq/eq when instantiated with int
+/// Can derive Hash/PartialOrd/Ord/PartialEq/Eq when instantiated with int
struct IntStr {
foo<int> a;
};
-/// Cannot derive hash/eq when instantiated with float but can derive partialeq
+/// Cannot derive Hash/Eq/Ord when instantiated with float but can derive PartialEq/PartialOrd
struct FloatStr {
foo<float> a;
};
diff --git a/tests/headers/derive-partialeq-anonfield.h b/tests/headers/derive-partialeq-anonfield.h
new file mode 100644
index 00000000..3bbe2bc3
--- /dev/null
+++ b/tests/headers/derive-partialeq-anonfield.h
@@ -0,0 +1,5 @@
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq
+
+struct rte_mbuf {
+ union {};
+} __attribute__((__aligned__(64)));
diff --git a/tests/headers/derive-partialeq-base.hpp b/tests/headers/derive-partialeq-base.hpp
new file mode 100644
index 00000000..989cbe69
--- /dev/null
+++ b/tests/headers/derive-partialeq-base.hpp
@@ -0,0 +1,8 @@
+// bindgen-flags: --with-derive-partialeq --impl-partialeq
+
+class Base {
+ int large[33];
+};
+
+class ShouldDerivePartialEq: Base {
+};
diff --git a/tests/headers/derive-partialeq-bitfield.hpp b/tests/headers/derive-partialeq-bitfield.hpp
new file mode 100644
index 00000000..ac2cac63
--- /dev/null
+++ b/tests/headers/derive-partialeq-bitfield.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --with-derive-partialeq --impl-partialeq
+
+class C {
+ bool a: 1;
+ bool b: 7;
+ int large_array[50];
+};
diff --git a/tests/headers/derive-partialeq-core.h b/tests/headers/derive-partialeq-core.h
new file mode 100644
index 00000000..6da5b786
--- /dev/null
+++ b/tests/headers/derive-partialeq-core.h
@@ -0,0 +1,5 @@
+// bindgen-flags: --with-derive-partialeq --impl-partialeq --use-core --raw-line "extern crate core;"
+
+struct C {
+ int large_array[420];
+};
diff --git a/tests/headers/derive-partialeq-pointer.hpp b/tests/headers/derive-partialeq-pointer.hpp
new file mode 100644
index 00000000..ce971e07
--- /dev/null
+++ b/tests/headers/derive-partialeq-pointer.hpp
@@ -0,0 +1,12 @@
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+
+struct a;
+class Bar {
+ a *b;
+};
+struct c {
+ union {};
+};
+struct a {
+ c d;
+};
diff --git a/tests/headers/derive-partialeq-union.hpp b/tests/headers/derive-partialeq-union.hpp
new file mode 100644
index 00000000..e2081a01
--- /dev/null
+++ b/tests/headers/derive-partialeq-union.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --with-derive-partialeq --impl-partialeq
+
+/// Deriving PartialEq for rust unions is not supported.
+union ShouldNotDerivePartialEq {
+ char a;
+ int b;
+};
diff --git a/tests/headers/derive-partialeq-union_1_0.hpp b/tests/headers/derive-partialeq-union_1_0.hpp
new file mode 100644
index 00000000..d546d77b
--- /dev/null
+++ b/tests/headers/derive-partialeq-union_1_0.hpp
@@ -0,0 +1,7 @@
+// 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/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h b/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h
new file mode 100644
index 00000000..c9189952
--- /dev/null
+++ b/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h
@@ -0,0 +1,3 @@
+typedef unsigned int uint32_t;
+
+uint32_t a = 18446744073709551611;
diff --git a/tests/headers/inherit-from-template-instantiation-with-vtable.hpp b/tests/headers/inherit-from-template-instantiation-with-vtable.hpp
new file mode 100644
index 00000000..562ca0e1
--- /dev/null
+++ b/tests/headers/inherit-from-template-instantiation-with-vtable.hpp
@@ -0,0 +1,37 @@
+// bindgen-flags: -- -std=c++14
+
+// Small test that we handle virtual tables correctly when deriving from a
+// template instantiation. This wasn't previously handled at all. Note that when
+// inheriting from a template parameter, the type that is instantiated might or
+// might not have a virtual table, and we have no way of knowing. We don't
+// handle that yet, so no test for it here.
+
+/// This should have an explicit vtable.
+template<class T>
+class BaseWithVtable {
+ T t;
+
+ virtual void hello();
+};
+
+/// This should not have an explicit vtable.
+class DerivedWithNoVirtualMethods : public BaseWithVtable<char*> {};
+
+/// This should not have an explicit vtable.
+class DerivedWithVirtualMethods : public BaseWithVtable<char*> {
+ virtual void zoidberg();
+};
+
+/// This should not have any vtable.
+template<class U>
+class BaseWithoutVtable {
+ U u;
+};
+
+/// This should have an explicit vtable.
+class DerivedWithVtable : public BaseWithoutVtable<char*> {
+ virtual void leela();
+};
+
+/// This should not have any vtable.
+class DerivedWithoutVtable : public BaseWithoutVtable<char*> {};
diff --git a/tests/headers/issue-1025-unknown-enum-repr.hpp b/tests/headers/issue-1025-unknown-enum-repr.hpp
new file mode 100644
index 00000000..589b3c25
--- /dev/null
+++ b/tests/headers/issue-1025-unknown-enum-repr.hpp
@@ -0,0 +1,4 @@
+
+template <typename> class a {
+ enum {};
+};
diff --git a/tests/headers/issue-1034.h b/tests/headers/issue-1034.h
new file mode 100644
index 00000000..8042fec6
--- /dev/null
+++ b/tests/headers/issue-1034.h
@@ -0,0 +1,4 @@
+
+struct S2 {
+ unsigned : 11
+};
diff --git a/tests/headers/issue-1040.h b/tests/headers/issue-1040.h
new file mode 100644
index 00000000..1d61d40d
--- /dev/null
+++ b/tests/headers/issue-1040.h
@@ -0,0 +1 @@
+unsigned long long g_107 = 18446744073709551615UL;
diff --git a/tests/headers/issue-648-derive-debug-with-padding.h b/tests/headers/issue-648-derive-debug-with-padding.h
index c9ec0210..f528c100 100644
--- a/tests/headers/issue-648-derive-debug-with-padding.h
+++ b/tests/headers/issue-648-derive-debug-with-padding.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq
/**
* We emit a `[u8; 63usize]` padding field for this struct, which cannot derive
* Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn't end
diff --git a/tests/headers/layout_array.h b/tests/headers/layout_array.h
index 6a20f7c3..239e52b1 100644
--- a/tests/headers/layout_array.h
+++ b/tests/headers/layout_array.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
diff --git a/tests/headers/layout_array_too_long.h b/tests/headers/layout_array_too_long.h
index a3ef3d20..1d8b1b63 100644
--- a/tests/headers/layout_array_too_long.h
+++ b/tests/headers/layout_array_too_long.h
@@ -1,4 +1,4 @@
-// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .*
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rustified-enum .*
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
diff --git a/tests/headers/no-hash-opaque.hpp b/tests/headers/no-hash-opaque.hpp
new file mode 100644
index 00000000..c1db2cd1
--- /dev/null
+++ b/tests/headers/no-hash-opaque.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --with-derive-hash --opaque-type "NoHash" --no-hash "NoHash"
+
+class NoHash {
+ int i;
+};
diff --git a/tests/headers/no-hash-whitelisted.hpp b/tests/headers/no-hash-whitelisted.hpp
new file mode 100644
index 00000000..77c90864
--- /dev/null
+++ b/tests/headers/no-hash-whitelisted.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --with-derive-hash --whitelist-type "NoHash" --no-hash "NoHash"
+
+class NoHash {
+ int i;
+};
diff --git a/tests/headers/no-partialeq-opaque.hpp b/tests/headers/no-partialeq-opaque.hpp
new file mode 100644
index 00000000..a5a03cd2
--- /dev/null
+++ b/tests/headers/no-partialeq-opaque.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --with-derive-partialeq --opaque-type "NoPartialEq" --no-partialeq "NoPartialEq"
+
+class NoPartialEq {
+ int i;
+};
diff --git a/tests/headers/no-partialeq-whitelisted.hpp b/tests/headers/no-partialeq-whitelisted.hpp
new file mode 100644
index 00000000..dba4e91f
--- /dev/null
+++ b/tests/headers/no-partialeq-whitelisted.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --with-derive-partialeq --whitelist-type "NoPartialEq" --no-partialeq "NoPartialEq"
+
+class NoPartialEq {
+ int i;
+};
diff --git a/tests/headers/no_copy_opaque.hpp b/tests/headers/no_copy_opaque.hpp
new file mode 100644
index 00000000..c21f213a
--- /dev/null
+++ b/tests/headers/no_copy_opaque.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --opaque-type "NoCopy" --no-copy "NoCopy"
+
+class NoCopy {
+ int i;
+};
diff --git a/tests/headers/no_copy_whitelisted.hpp b/tests/headers/no_copy_whitelisted.hpp
new file mode 100644
index 00000000..db44a8a7
--- /dev/null
+++ b/tests/headers/no_copy_whitelisted.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: --whitelist-type "NoCopy" --no-copy "NoCopy"
+
+class NoCopy {
+ int i;
+};
diff --git a/tests/headers/opaque-template-inst-member.hpp b/tests/headers/opaque-template-inst-member.hpp
index 4cb3dd72..6516aa56 100644
--- a/tests/headers/opaque-template-inst-member.hpp
+++ b/tests/headers/opaque-template-inst-member.hpp
@@ -1,4 +1,4 @@
-// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash --with-derive-partialeq --with-derive-eq
+// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash --with-derive-partialeq --impl-partialeq --with-derive-eq
template<typename T>
class OpaqueTemplate {
@@ -6,14 +6,14 @@ class OpaqueTemplate {
bool mCannotDebug[400];
};
-/// This should not end up deriving Debug/Hash/PartialEq because its `mBlah` field cannot derive
-/// Debug/Hash/PartialEq because the instantiation's definition cannot derive Debug/Hash/PartialEq.
+/// This should not end up deriving Debug/Hash because its `mBlah` field cannot derive
+/// Debug/Hash because the instantiation's definition cannot derive Debug/Hash.
class ContainsOpaqueTemplate {
OpaqueTemplate<int> mBlah;
int mBaz;
};
-/// This shold not end up deriving Debug/Hash/PartialEq either, for similar reasons, although
+/// This should not end up deriving Debug/Hash either, for similar reasons, although
/// we're exercising base member edges now.
class InheritsOpaqueTemplate : public OpaqueTemplate<bool> {
char* wow;
diff --git a/tests/headers/sentry-defined-multiple-times.hpp b/tests/headers/sentry-defined-multiple-times.hpp
new file mode 100644
index 00000000..d44837d0
--- /dev/null
+++ b/tests/headers/sentry-defined-multiple-times.hpp
@@ -0,0 +1,85 @@
+// bindgen-flags: --enable-cxx-namespaces -- -std=c++11
+
+// `Wrapper::sentry` and `sentry` should be emitted as `Wrapper_sentry` and
+// `sentry` respectively, but instead `Wrapper::sentry` is named just `sentry`
+// which leads to compilation errors.
+//
+// Note: if there is no namespace, then we don't run into problems. Similarly,
+// making the `Wrapper::sentry` definition inline in `Wrapper`, rather than
+// declared inline with an out of line definition, makes the problem go away as
+// well.
+
+namespace whatever {
+ template <typename, typename>
+ class Wrapper {
+ // Declaration of Wrapper::sentry
+ class sentry;
+ };
+
+ // Definition of Wrapper::sentry
+ template <typename f, typename h>
+ class Wrapper<f, h>::sentry {
+ int i_am_wrapper_sentry;
+ };
+
+ class sentry {
+ bool i_am_plain_sentry;
+ };
+
+ // Ok, that was the original bug report. While we're here, let's just try
+ // lots of different things that could go wrong and make sure we handle them
+ // right.
+
+ class NotTemplateWrapper {
+ class sentry;
+ };
+
+ class NotTemplateWrapper::sentry {
+ char i_am_not_template_wrapper_sentry;
+ };
+
+ class InlineNotTemplateWrapper {
+ class sentry {
+ bool i_am_inline_not_template_wrapper_sentry;
+ };
+ };
+
+ template <typename, typename>
+ class InlineTemplateWrapper {
+ class sentry {
+ int i_am_inline_template_wrapper_sentry;
+ };
+ };
+
+ class OuterDoubleWrapper {
+ class InnerDoubleWrapper {
+ class sentry;
+ };
+ };
+
+ class OuterDoubleWrapper::InnerDoubleWrapper::sentry {
+ int i_am_double_wrapper_sentry;
+ };
+
+ class OuterDoubleInlineWrapper {
+ class InnerDoubleInlineWrapper {
+ class sentry {
+ int i_am_double_wrapper_inline_sentry;
+ };
+ };
+ };
+}
+
+template <typename, typename>
+class OutsideNamespaceWrapper {
+ class sentry;
+};
+
+template <typename f, typename h>
+class OutsideNamespaceWrapper<f, h>::sentry {
+ int i_am_outside_namespace_wrapper_sentry;
+};
+
+class sentry {
+ int i_am_outside_namespace_sentry;
+};
diff --git a/tests/headers/underscore.hpp b/tests/headers/underscore.hpp
new file mode 100644
index 00000000..1c9371f1
--- /dev/null
+++ b/tests/headers/underscore.hpp
@@ -0,0 +1,3 @@
+const int _ = 10;
+
+typedef struct { unsigned char _[8]; } ptr_t; \ No newline at end of file
diff --git a/tests/headers/union_bitfield.h b/tests/headers/union_bitfield.h
new file mode 100644
index 00000000..99072957
--- /dev/null
+++ b/tests/headers/union_bitfield.h
@@ -0,0 +1,10 @@
+// bindgen-flags: --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;
+};
diff --git a/tests/headers/union_bitfield_1_0.h b/tests/headers/union_bitfield_1_0.h
new file mode 100644
index 00000000..06b61ad7
--- /dev/null
+++ b/tests/headers/union_bitfield_1_0.h
@@ -0,0 +1,14 @@
+// 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/tests/headers/whitelisted-item-references-no-hash.hpp b/tests/headers/whitelisted-item-references-no-hash.hpp
new file mode 100644
index 00000000..e656d32d
--- /dev/null
+++ b/tests/headers/whitelisted-item-references-no-hash.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --with-derive-hash --whitelist-type "WhitelistMe" --no-hash "NoHash"
+
+struct NoHash {};
+
+class WhitelistMe {
+ NoHash a;
+};
diff --git a/tests/headers/whitelisted-item-references-no-partialeq.hpp b/tests/headers/whitelisted-item-references-no-partialeq.hpp
new file mode 100644
index 00000000..d9d3d431
--- /dev/null
+++ b/tests/headers/whitelisted-item-references-no-partialeq.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --with-derive-partialeq --whitelist-type "WhitelistMe" --no-partialeq "NoPartialEq"
+
+struct NoPartialEq {};
+
+class WhitelistMe {
+ NoPartialEq a;
+};
diff --git a/tests/headers/whitelisted_item_references_no_copy.hpp b/tests/headers/whitelisted_item_references_no_copy.hpp
new file mode 100644
index 00000000..755bbbdd
--- /dev/null
+++ b/tests/headers/whitelisted_item_references_no_copy.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --whitelist-type "WhitelistMe" --no-copy "NoCopy"
+
+struct NoCopy {};
+
+class WhitelistMe {
+ NoCopy a;
+};
diff --git a/tests/headers/win32-thiscall_1_0.hpp b/tests/headers/win32-thiscall_1_0.hpp
new file mode 100644
index 00000000..5907c76e
--- /dev/null
+++ b/tests/headers/win32-thiscall_1_0.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --rust-target 1.0 -- --target=i686-pc-windows-msvc
+
+class Foo {
+ public:
+ void test();
+ int test2(int var);
+};
diff --git a/tests/headers/win32-thiscall_nightly.hpp b/tests/headers/win32-thiscall_nightly.hpp
new file mode 100644
index 00000000..2c9f2f17
--- /dev/null
+++ b/tests/headers/win32-thiscall_nightly.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_thiscall)]' -- --target=i686-pc-windows-msvc
+
+class Foo {
+ public:
+ void test();
+ int test2(int var);
+};
diff --git a/tests/headers/zero-sized-array.hpp b/tests/headers/zero-sized-array.hpp
new file mode 100644
index 00000000..ae6d0554
--- /dev/null
+++ b/tests/headers/zero-sized-array.hpp
@@ -0,0 +1,45 @@
+// These classes are technically zero-sized, but despite that they still don't
+// get an `_address` field inserted.
+
+/**
+ * Bizarrely enough, this should *not* get an `_address` field.
+ */
+class ZeroSizedArray {
+ char arr[0];
+};
+
+/**
+ * And nor should this get an `_address` field.
+ */
+class ContainsZeroSizedArray {
+ ZeroSizedArray zsa;
+};
+
+/**
+ * Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted
+ * either.
+ */
+class InheritsZeroSizedArray : ZeroSizedArray {};
+
+// These are dynamically sized, which means that `sizeof` yields `0` but it
+// isn't really true. We shouldn't add an `_address` field to them.
+
+/**
+ * And this should not get an `_address` field either.
+ */
+class DynamicallySizedArray {
+ char arr[];
+};
+
+/**
+ * No `_address` field here either.
+ */
+class ContainsDynamicallySizedArray {
+ DynamicallySizedArray dsa;
+};
+
+// Note: this is disallowed:
+//
+// error: base class 'DynamicallySizedArray' has a flexible array member
+//
+// class InheritsDynamicallySizedArray : DynamicallySizedArray {};
diff --git a/tests/rustfmt.toml b/tests/rustfmt.toml
index e69de29b..a9e57337 100644
--- a/tests/rustfmt.toml
+++ b/tests/rustfmt.toml
@@ -0,0 +1 @@
+error_on_line_overflow_comments = false
diff --git a/tests/tests.rs b/tests/tests.rs
index 1e02da2d..5b12861f 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -235,18 +235,13 @@ fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> {
}
}
- // Windows platform has various different conventions than *nix platforms,
- // e.g. default enum underlying type, struct padding, mangling. Most tests
- // were written and checked on Linux and macOS, and thus they could fail on
- // Windows. We just make those tests targetting Linux instead as far as one
- // isn't annotated for a specific target.
- if cfg!(target_os = "windows") {
- if flags.iter().all(|flag| !flag.starts_with("--target=")) {
- if !flags.iter().any(|flag| flag == "--") {
- flags.push("--".into());
- }
- flags.push("--target=x86_64-unknown-linux".into());
+ // Different platforms have various different conventions like struct padding, mangling, etc.
+ // We make the default target as x86_64-unknown-linux
+ if flags.iter().all(|flag| !flag.starts_with("--target=")) {
+ if !flags.iter().any(|flag| flag == "--") {
+ flags.push("--".into());
}
+ flags.push("--target=x86_64-unknown-linux".into());
}
// Fool builder_from_flags() into believing it has real env::args_os...
@@ -261,6 +256,9 @@ fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> {
let prepend = [
"bindgen",
+ // We format in `compare_generated_header` ourselves to have a little
+ // more control.
+ "--no-rustfmt-bindings",
"--with-derive-default",
header_str,
"--raw-line",
@@ -307,6 +305,7 @@ include!(concat!(env!("OUT_DIR"), "/tests.rs"));
fn test_header_contents() {
let actual = builder()
.header_contents("test.h", "int foo(const char* a);")
+ .clang_arg("--target=x86_64-unknown-linux")
.generate()
.unwrap()
.to_string();
@@ -335,6 +334,7 @@ fn test_multiple_header_calls_in_builder() {
"/tests/headers/func_ptr.h"
))
.header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h"))
+ .clang_arg("--target=x86_64-unknown-linux")
.generate()
.unwrap()
.to_string();