code_ownership 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (445) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +30 -27
  3. data/bin/codeownership +1 -0
  4. data/ext/cargo-vendor/bindgen-0.72.1/.cargo-checksum.json +1 -0
  5. data/ext/cargo-vendor/bindgen-0.72.1/.cargo_vcs_info.json +6 -0
  6. data/ext/cargo-vendor/bindgen-0.72.1/Cargo.lock +485 -0
  7. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/Cargo.toml +72 -38
  8. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/Cargo.toml.orig +26 -28
  9. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/README.md +2 -2
  10. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/build.rs +2 -2
  11. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/callbacks.rs +114 -10
  12. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/clang.rs +184 -83
  13. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/bitfield_unit.rs +20 -10
  14. data/ext/cargo-vendor/bindgen-0.72.1/codegen/bitfield_unit_raw_ref_macros.rs +191 -0
  15. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/bitfield_unit_tests.rs +4 -4
  16. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/dyngen.rs +77 -20
  17. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/error.rs +2 -3
  18. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/helpers.rs +106 -66
  19. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/impl_debug.rs +32 -34
  20. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/impl_partialeq.rs +5 -5
  21. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/mod.rs +1197 -679
  22. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/postprocessing/merge_extern_blocks.rs +3 -3
  23. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/postprocessing/sort_semantically.rs +3 -3
  24. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/serialize.rs +33 -34
  25. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/struct_layout.rs +33 -26
  26. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/deps.rs +1 -1
  27. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/diagnostics.rs +22 -65
  28. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/extra_assertions.rs +1 -1
  29. data/ext/cargo-vendor/bindgen-0.72.1/features.rs +570 -0
  30. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/derive.rs +69 -75
  31. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/has_destructor.rs +5 -6
  32. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/has_float.rs +13 -17
  33. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/has_type_param_in_array.rs +22 -32
  34. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/has_vtable.rs +11 -16
  35. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/mod.rs +15 -20
  36. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/sizedness.rs +13 -21
  37. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/analysis/template_params.rs +20 -26
  38. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/annotations.rs +18 -15
  39. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/comment.rs +2 -2
  40. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/comp.rs +54 -29
  41. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/context.rs +205 -136
  42. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/derive.rs +5 -10
  43. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/dot.rs +3 -4
  44. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/enum_ty.rs +5 -7
  45. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/function.rs +27 -28
  46. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/int.rs +7 -6
  47. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/item.rs +92 -132
  48. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/item_kind.rs +7 -7
  49. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/layout.rs +11 -23
  50. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/module.rs +2 -2
  51. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/objc.rs +22 -33
  52. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/template.rs +26 -33
  53. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/traversal.rs +4 -5
  54. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/ty.rs +63 -88
  55. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/var.rs +73 -38
  56. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/lib.rs +186 -144
  57. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/log_stubs.rs +6 -0
  58. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/options/as_args.rs +1 -1
  59. data/ext/cargo-vendor/bindgen-0.72.1/options/cli.rs +1151 -0
  60. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/options/mod.rs +234 -27
  61. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/regex_set.rs +23 -28
  62. data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/time.rs +4 -4
  63. data/ext/cargo-vendor/rb-sys-0.9.130/.cargo-checksum.json +1 -0
  64. data/ext/cargo-vendor/rb-sys-0.9.130/.cargo_vcs_info.json +6 -0
  65. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/Cargo.lock +23 -31
  66. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/Cargo.toml +5 -4
  67. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/Cargo.toml.orig +5 -4
  68. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/build/main.rs +7 -1
  69. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/build/stable_api_config.rs +30 -6
  70. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/build/version.rs +14 -6
  71. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/bindings.rs +1 -0
  72. data/ext/cargo-vendor/rb-sys-0.9.130/src/macros.rs +701 -0
  73. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/memory.rs +17 -6
  74. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/stable_api/compiled.c +169 -10
  75. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/stable_api/compiled.rs +209 -14
  76. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_2_7.rs +770 -0
  77. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_3_0.rs +773 -0
  78. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_3_1.rs +766 -0
  79. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_3_2.rs +764 -0
  80. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_3_3.rs +777 -0
  81. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_3_4.rs +788 -0
  82. data/ext/cargo-vendor/rb-sys-0.9.130/src/stable_api/ruby_4_0.rs +784 -0
  83. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/stable_api.rs +213 -9
  84. data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/utils.rs +12 -7
  85. data/ext/cargo-vendor/rb-sys-build-0.9.130/.cargo-checksum.json +1 -0
  86. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/.cargo_vcs_info.json +1 -1
  87. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/Cargo.lock +19 -27
  88. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/Cargo.toml +8 -3
  89. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/Cargo.toml.orig +4 -3
  90. data/ext/cargo-vendor/rb-sys-build-0.9.130/src/bindings/gc_stress.rs +303 -0
  91. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/bindings/stable_api.rs +102 -11
  92. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/bindings.rs +19 -13
  93. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/cc.rs +1 -1
  94. data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/rb_config.rs +199 -2
  95. data/ext/cargo-vendor/rb-sys-build-0.9.130/tests/fixtures/rubyopt_stdout.rb +1 -0
  96. data/ext/cargo-vendor/rb-sys-build-0.9.130/tests/rubyopt.rs +17 -0
  97. data/ext/cargo-vendor/rb-sys-env-0.2.3/.cargo-checksum.json +1 -0
  98. data/ext/cargo-vendor/rb-sys-env-0.2.3/.cargo_vcs_info.json +6 -0
  99. data/ext/cargo-vendor/rb-sys-env-0.2.3/Cargo.lock +7 -0
  100. data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/Cargo.toml +2 -2
  101. data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/Cargo.toml.orig +2 -2
  102. data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/readme.md +0 -2
  103. data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/src/ruby_version.rs +3 -1
  104. data/ext/cargo-vendor/rustc-hash-2.1.3/.cargo-checksum.json +1 -0
  105. data/ext/cargo-vendor/rustc-hash-2.1.3/.cargo_vcs_info.json +6 -0
  106. data/ext/cargo-vendor/rustc-hash-2.1.3/.github/workflows/rust.yml +73 -0
  107. data/ext/cargo-vendor/rustc-hash-2.1.3/CHANGELOG.md +41 -0
  108. data/ext/cargo-vendor/rustc-hash-2.1.3/CODE_OF_CONDUCT.md +3 -0
  109. data/ext/cargo-vendor/rustc-hash-2.1.3/Cargo.lock +90 -0
  110. data/ext/cargo-vendor/rustc-hash-2.1.3/Cargo.toml +50 -0
  111. data/ext/cargo-vendor/rustc-hash-2.1.3/Cargo.toml.orig +20 -0
  112. data/ext/cargo-vendor/rustc-hash-2.1.3/LICENSE-APACHE +176 -0
  113. data/ext/cargo-vendor/rustc-hash-2.1.3/LICENSE-MIT +23 -0
  114. data/ext/cargo-vendor/rustc-hash-2.1.3/README.md +42 -0
  115. data/ext/cargo-vendor/rustc-hash-2.1.3/src/lib.rs +472 -0
  116. data/ext/cargo-vendor/rustc-hash-2.1.3/src/random_state.rs +101 -0
  117. data/ext/cargo-vendor/rustc-hash-2.1.3/src/seeded_state.rs +76 -0
  118. data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/.cargo-checksum.json +1 -1
  119. data/ext/cargo-vendor/serde-1.0.229/.cargo_vcs_info.json +6 -0
  120. data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/Cargo.lock +13 -13
  121. data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/Cargo.toml +2 -2
  122. data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/Cargo.toml.orig +2 -2
  123. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde-1.0.229}/README.md +3 -3
  124. data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/build.rs +2 -2
  125. data/ext/cargo-vendor/{serde_core-1.0.228/src → serde-1.0.229/src/core}/de/impls.rs +4 -4
  126. data/ext/cargo-vendor/{serde_core-1.0.228/src → serde-1.0.229/src/core}/lib.rs +2 -2
  127. data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/lib.rs +3 -3
  128. data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/.cargo-checksum.json +1 -1
  129. data/ext/cargo-vendor/serde_core-1.0.229/.cargo_vcs_info.json +6 -0
  130. data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/Cargo.lock +11 -11
  131. data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/Cargo.toml +2 -2
  132. data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/Cargo.toml.orig +2 -2
  133. data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/build.rs +5 -5
  134. data/ext/cargo-vendor/{serde-1.0.228/src/core → serde_core-1.0.229/src}/de/impls.rs +4 -4
  135. data/ext/cargo-vendor/{serde-1.0.228/src/core → serde_core-1.0.229/src}/lib.rs +2 -2
  136. data/ext/cargo-vendor/serde_derive-1.0.229/.cargo-checksum.json +1 -0
  137. data/ext/cargo-vendor/serde_derive-1.0.229/.cargo_vcs_info.json +6 -0
  138. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/Cargo.lock +29 -18
  139. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/Cargo.toml +3 -3
  140. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/Cargo.toml.orig +2 -2
  141. data/ext/cargo-vendor/{serde-1.0.228 → serde_derive-1.0.229}/README.md +3 -3
  142. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/bound.rs +80 -59
  143. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/enum_adjacently.rs +46 -45
  144. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/enum_externally.rs +3 -2
  145. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de.rs +10 -7
  146. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/ast.rs +15 -8
  147. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/attr.rs +18 -31
  148. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/ctxt.rs +3 -4
  149. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/receiver.rs +2 -2
  150. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/lib.rs +1 -1
  151. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/pretend.rs +7 -7
  152. data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/ser.rs +94 -94
  153. data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/.cargo-checksum.json +1 -1
  154. data/ext/cargo-vendor/serde_magnus-0.11.0/.cargo_vcs_info.json +6 -0
  155. data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/Cargo.lock +71 -73
  156. data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/Cargo.toml +2 -2
  157. data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/Cargo.toml.orig +2 -2
  158. data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/README.md +1 -1
  159. data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/deserializer.rs +2 -2
  160. data/ext/cargo-vendor/syn-3.0.9/.cargo-checksum.json +1 -0
  161. data/ext/cargo-vendor/syn-3.0.9/.cargo_vcs_info.json +6 -0
  162. data/ext/cargo-vendor/syn-3.0.9/Cargo.lock +1948 -0
  163. data/ext/cargo-vendor/syn-3.0.9/Cargo.toml +268 -0
  164. data/ext/cargo-vendor/syn-3.0.9/Cargo.toml.orig +95 -0
  165. data/ext/cargo-vendor/{lazycell-1.3.0 → syn-3.0.9}/LICENSE-APACHE +0 -25
  166. data/ext/cargo-vendor/syn-3.0.9/README.md +297 -0
  167. data/ext/cargo-vendor/syn-3.0.9/benches/file.rs +59 -0
  168. data/ext/cargo-vendor/syn-3.0.9/benches/rust.rs +189 -0
  169. data/ext/cargo-vendor/syn-3.0.9/src/attr.rs +841 -0
  170. data/ext/cargo-vendor/syn-3.0.9/src/bigint.rs +68 -0
  171. data/ext/cargo-vendor/syn-3.0.9/src/buffer.rs +462 -0
  172. data/ext/cargo-vendor/syn-3.0.9/src/classify.rs +311 -0
  173. data/ext/cargo-vendor/syn-3.0.9/src/custom_keyword.rs +260 -0
  174. data/ext/cargo-vendor/syn-3.0.9/src/custom_punctuation.rs +305 -0
  175. data/ext/cargo-vendor/syn-3.0.9/src/data.rs +489 -0
  176. data/ext/cargo-vendor/syn-3.0.9/src/derive.rs +260 -0
  177. data/ext/cargo-vendor/syn-3.0.9/src/discouraged.rs +233 -0
  178. data/ext/cargo-vendor/syn-3.0.9/src/drops.rs +58 -0
  179. data/ext/cargo-vendor/syn-3.0.9/src/error.rs +552 -0
  180. data/ext/cargo-vendor/syn-3.0.9/src/export.rs +73 -0
  181. data/ext/cargo-vendor/syn-3.0.9/src/expr.rs +4249 -0
  182. data/ext/cargo-vendor/syn-3.0.9/src/ext.rs +180 -0
  183. data/ext/cargo-vendor/syn-3.0.9/src/file.rs +136 -0
  184. data/ext/cargo-vendor/syn-3.0.9/src/fixup.rs +773 -0
  185. data/ext/cargo-vendor/syn-3.0.9/src/gen/clone.rs +2394 -0
  186. data/ext/cargo-vendor/syn-3.0.9/src/gen/debug.rs +3399 -0
  187. data/ext/cargo-vendor/syn-3.0.9/src/gen/eq.rs +2459 -0
  188. data/ext/cargo-vendor/syn-3.0.9/src/gen/fold.rs +3934 -0
  189. data/ext/cargo-vendor/syn-3.0.9/src/gen/hash.rs +3040 -0
  190. data/ext/cargo-vendor/syn-3.0.9/src/gen/token.css +744 -0
  191. data/ext/cargo-vendor/syn-3.0.9/src/gen/visit.rs +4037 -0
  192. data/ext/cargo-vendor/syn-3.0.9/src/gen/visit_mut.rs +3824 -0
  193. data/ext/cargo-vendor/syn-3.0.9/src/generics.rs +1490 -0
  194. data/ext/cargo-vendor/syn-3.0.9/src/group.rs +294 -0
  195. data/ext/cargo-vendor/syn-3.0.9/src/ident.rs +109 -0
  196. data/ext/cargo-vendor/syn-3.0.9/src/item.rs +3923 -0
  197. data/ext/cargo-vendor/syn-3.0.9/src/lib.rs +1132 -0
  198. data/ext/cargo-vendor/syn-3.0.9/src/lifetime.rs +193 -0
  199. data/ext/cargo-vendor/syn-3.0.9/src/lit.rs +1881 -0
  200. data/ext/cargo-vendor/syn-3.0.9/src/lookahead.rs +350 -0
  201. data/ext/cargo-vendor/syn-3.0.9/src/mac.rs +225 -0
  202. data/ext/cargo-vendor/syn-3.0.9/src/macros.rs +151 -0
  203. data/ext/cargo-vendor/syn-3.0.9/src/meta.rs +427 -0
  204. data/ext/cargo-vendor/syn-3.0.9/src/op.rs +219 -0
  205. data/ext/cargo-vendor/syn-3.0.9/src/parse.rs +1420 -0
  206. data/ext/cargo-vendor/syn-3.0.9/src/parse_macro_input.rs +128 -0
  207. data/ext/cargo-vendor/syn-3.0.9/src/parse_quote.rs +261 -0
  208. data/ext/cargo-vendor/syn-3.0.9/src/pat.rs +994 -0
  209. data/ext/cargo-vendor/syn-3.0.9/src/path.rs +972 -0
  210. data/ext/cargo-vendor/syn-3.0.9/src/precedence.rs +210 -0
  211. data/ext/cargo-vendor/syn-3.0.9/src/print.rs +16 -0
  212. data/ext/cargo-vendor/syn-3.0.9/src/punctuated.rs +1200 -0
  213. data/ext/cargo-vendor/syn-3.0.9/src/restriction.rs +160 -0
  214. data/ext/cargo-vendor/syn-3.0.9/src/scan_expr.rs +270 -0
  215. data/ext/cargo-vendor/syn-3.0.9/src/sealed.rs +4 -0
  216. data/ext/cargo-vendor/syn-3.0.9/src/span.rs +63 -0
  217. data/ext/cargo-vendor/syn-3.0.9/src/spanned.rs +118 -0
  218. data/ext/cargo-vendor/syn-3.0.9/src/stmt.rs +536 -0
  219. data/ext/cargo-vendor/syn-3.0.9/src/thread.rs +60 -0
  220. data/ext/cargo-vendor/syn-3.0.9/src/token.rs +1103 -0
  221. data/ext/cargo-vendor/syn-3.0.9/src/tt.rs +97 -0
  222. data/ext/cargo-vendor/syn-3.0.9/src/ty.rs +1347 -0
  223. data/ext/cargo-vendor/syn-3.0.9/src/verbatim.rs +32 -0
  224. data/ext/cargo-vendor/syn-3.0.9/src/whitespace.rs +65 -0
  225. data/ext/cargo-vendor/syn-3.0.9/tests/common/eq.rs +939 -0
  226. data/ext/cargo-vendor/syn-3.0.9/tests/common/mod.rs +6 -0
  227. data/ext/cargo-vendor/syn-3.0.9/tests/common/parse.rs +51 -0
  228. data/ext/cargo-vendor/syn-3.0.9/tests/common/visit.rs +119 -0
  229. data/ext/cargo-vendor/syn-3.0.9/tests/debug/gen.rs +5394 -0
  230. data/ext/cargo-vendor/syn-3.0.9/tests/debug/mod.rs +147 -0
  231. data/ext/cargo-vendor/syn-3.0.9/tests/macros/mod.rs +7 -0
  232. data/ext/cargo-vendor/syn-3.0.9/tests/regression/issue1108.rs +5 -0
  233. data/ext/cargo-vendor/syn-3.0.9/tests/regression/issue1235.rs +32 -0
  234. data/ext/cargo-vendor/syn-3.0.9/tests/regression.rs +5 -0
  235. data/ext/cargo-vendor/syn-3.0.9/tests/repo/mod.rs +789 -0
  236. data/ext/cargo-vendor/syn-3.0.9/tests/repo/progress.rs +37 -0
  237. data/ext/cargo-vendor/syn-3.0.9/tests/snapshot/mod.rs +68 -0
  238. data/ext/cargo-vendor/syn-3.0.9/tests/test_attribute.rs +231 -0
  239. data/ext/cargo-vendor/syn-3.0.9/tests/test_derive_input.rs +801 -0
  240. data/ext/cargo-vendor/syn-3.0.9/tests/test_expr.rs +1721 -0
  241. data/ext/cargo-vendor/syn-3.0.9/tests/test_generics.rs +363 -0
  242. data/ext/cargo-vendor/syn-3.0.9/tests/test_grouping.rs +59 -0
  243. data/ext/cargo-vendor/syn-3.0.9/tests/test_ident.rs +87 -0
  244. data/ext/cargo-vendor/syn-3.0.9/tests/test_item.rs +374 -0
  245. data/ext/cargo-vendor/syn-3.0.9/tests/test_lit.rs +335 -0
  246. data/ext/cargo-vendor/syn-3.0.9/tests/test_meta.rs +180 -0
  247. data/ext/cargo-vendor/syn-3.0.9/tests/test_parse_buffer.rs +104 -0
  248. data/ext/cargo-vendor/syn-3.0.9/tests/test_parse_quote.rs +175 -0
  249. data/ext/cargo-vendor/syn-3.0.9/tests/test_parse_stream.rs +187 -0
  250. data/ext/cargo-vendor/syn-3.0.9/tests/test_pat.rs +158 -0
  251. data/ext/cargo-vendor/syn-3.0.9/tests/test_path.rs +117 -0
  252. data/ext/cargo-vendor/syn-3.0.9/tests/test_precedence.rs +560 -0
  253. data/ext/cargo-vendor/syn-3.0.9/tests/test_punctuated.rs +92 -0
  254. data/ext/cargo-vendor/syn-3.0.9/tests/test_receiver.rs +275 -0
  255. data/ext/cargo-vendor/syn-3.0.9/tests/test_round_trip.rs +226 -0
  256. data/ext/cargo-vendor/syn-3.0.9/tests/test_shebang.rs +77 -0
  257. data/ext/cargo-vendor/syn-3.0.9/tests/test_size.rs +54 -0
  258. data/ext/cargo-vendor/syn-3.0.9/tests/test_stmt.rs +378 -0
  259. data/ext/cargo-vendor/syn-3.0.9/tests/test_token_trees.rs +38 -0
  260. data/ext/cargo-vendor/syn-3.0.9/tests/test_ty.rs +479 -0
  261. data/ext/cargo-vendor/syn-3.0.9/tests/test_unparenthesize.rs +71 -0
  262. data/ext/cargo-vendor/syn-3.0.9/tests/test_visibility.rs +193 -0
  263. data/ext/cargo-vendor/syn-3.0.9/tests/zzz_stable.rs +33 -0
  264. data/ext/code_ownership/Cargo.toml +1 -1
  265. data/ext/code_ownership/src/lib.rs +2 -2
  266. data/lib/code_ownership/version.rb +1 -1
  267. data/lib/code_ownership.rb +1 -1
  268. metadata +400 -293
  269. data/ext/cargo-vendor/bindgen-0.69.5/.cargo-checksum.json +0 -1
  270. data/ext/cargo-vendor/bindgen-0.69.5/.cargo_vcs_info.json +0 -6
  271. data/ext/cargo-vendor/bindgen-0.69.5/features.rs +0 -296
  272. data/ext/cargo-vendor/lazycell-1.3.0/.cargo-checksum.json +0 -1
  273. data/ext/cargo-vendor/lazycell-1.3.0/.cargo_vcs_info.json +0 -5
  274. data/ext/cargo-vendor/lazycell-1.3.0/CHANGELOG.md +0 -197
  275. data/ext/cargo-vendor/lazycell-1.3.0/Cargo.toml +0 -34
  276. data/ext/cargo-vendor/lazycell-1.3.0/Cargo.toml.orig +0 -27
  277. data/ext/cargo-vendor/lazycell-1.3.0/LICENSE-MIT +0 -26
  278. data/ext/cargo-vendor/lazycell-1.3.0/README.md +0 -73
  279. data/ext/cargo-vendor/lazycell-1.3.0/src/lib.rs +0 -680
  280. data/ext/cargo-vendor/lazycell-1.3.0/src/serde_impl.rs +0 -86
  281. data/ext/cargo-vendor/rb-sys-0.9.117/.cargo-checksum.json +0 -1
  282. data/ext/cargo-vendor/rb-sys-0.9.117/.cargo_vcs_info.json +0 -6
  283. data/ext/cargo-vendor/rb-sys-0.9.117/src/macros.rs +0 -371
  284. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_2_6.rs +0 -324
  285. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_2_7.rs +0 -324
  286. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_3_0.rs +0 -332
  287. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_3_1.rs +0 -325
  288. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_3_2.rs +0 -323
  289. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_3_3.rs +0 -339
  290. data/ext/cargo-vendor/rb-sys-0.9.117/src/stable_api/ruby_3_4.rs +0 -339
  291. data/ext/cargo-vendor/rb-sys-build-0.9.117/.cargo-checksum.json +0 -1
  292. data/ext/cargo-vendor/rb-sys-env-0.2.2/.cargo-checksum.json +0 -1
  293. data/ext/cargo-vendor/rb-sys-env-0.2.2/.cargo_vcs_info.json +0 -6
  294. data/ext/cargo-vendor/rustc-hash-1.1.0/.cargo-checksum.json +0 -1
  295. data/ext/cargo-vendor/rustc-hash-1.1.0/.cargo_vcs_info.json +0 -5
  296. data/ext/cargo-vendor/rustc-hash-1.1.0/CODE_OF_CONDUCT.md +0 -40
  297. data/ext/cargo-vendor/rustc-hash-1.1.0/Cargo.toml +0 -25
  298. data/ext/cargo-vendor/rustc-hash-1.1.0/Cargo.toml.orig +0 -13
  299. data/ext/cargo-vendor/rustc-hash-1.1.0/LICENSE-APACHE +0 -201
  300. data/ext/cargo-vendor/rustc-hash-1.1.0/README.md +0 -38
  301. data/ext/cargo-vendor/rustc-hash-1.1.0/src/lib.rs +0 -148
  302. data/ext/cargo-vendor/serde-1.0.228/.cargo_vcs_info.json +0 -6
  303. data/ext/cargo-vendor/serde_core-1.0.228/.cargo_vcs_info.json +0 -6
  304. data/ext/cargo-vendor/serde_derive-1.0.228/.cargo-checksum.json +0 -1
  305. data/ext/cargo-vendor/serde_derive-1.0.228/.cargo_vcs_info.json +0 -6
  306. data/ext/cargo-vendor/serde_magnus-0.10.0/.cargo_vcs_info.json +0 -6
  307. /data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/LICENSE +0 -0
  308. /data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/codegen/postprocessing/mod.rs +0 -0
  309. /data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/ir/mod.rs +0 -0
  310. /data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/options/helpers.rs +0 -0
  311. /data/ext/cargo-vendor/{bindgen-0.69.5 → bindgen-0.72.1}/parse.rs +0 -0
  312. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/LICENSE-APACHE +0 -0
  313. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/LICENSE-MIT +0 -0
  314. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/bin/release.sh +0 -0
  315. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/build/features.rs +0 -0
  316. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/readme.md +0 -0
  317. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/hidden.rs +0 -0
  318. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/lib.rs +0 -0
  319. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/ruby_abi_version.rs +0 -0
  320. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/special_consts.rs +0 -0
  321. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/symbol.rs +0 -0
  322. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/tracking_allocator.rs +0 -0
  323. /data/ext/cargo-vendor/{rb-sys-0.9.117 → rb-sys-0.9.130}/src/value_type.rs +0 -0
  324. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/LICENSE-APACHE +0 -0
  325. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/LICENSE-MIT +0 -0
  326. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/bindings/sanitizer.rs +0 -0
  327. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/bindings/wrapper.h +0 -0
  328. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/lib.rs +0 -0
  329. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/rb_config/flags.rs +0 -0
  330. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/rb_config/library.rs +0 -0
  331. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/rb_config/search_path.rs +0 -0
  332. /data/ext/cargo-vendor/{rb-sys-build-0.9.117 → rb-sys-build-0.9.130}/src/utils.rs +0 -0
  333. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/LICENSE-APACHE +0 -0
  334. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/LICENSE-MIT +0 -0
  335. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/build.rs +0 -0
  336. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/src/defines.rs +0 -0
  337. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/src/lib.rs +0 -0
  338. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/src/rb_env.rs +0 -0
  339. /data/ext/cargo-vendor/{rb-sys-env-0.2.2 → rb-sys-env-0.2.3}/src/utils.rs +0 -0
  340. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/LICENSE-APACHE +0 -0
  341. /data/ext/cargo-vendor/{rustc-hash-1.1.0 → serde-1.0.229}/LICENSE-MIT +0 -0
  342. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/crates-io.md +0 -0
  343. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/crate_root.rs +0 -0
  344. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/de/ignored_any.rs +0 -0
  345. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/de/mod.rs +0 -0
  346. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/de/value.rs +0 -0
  347. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/format.rs +0 -0
  348. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/macros.rs +0 -0
  349. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/private/content.rs +0 -0
  350. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/private/doc.rs +0 -0
  351. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/private/mod.rs +0 -0
  352. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/private/seed.rs +0 -0
  353. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/private/size_hint.rs +0 -0
  354. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/private/string.rs +0 -0
  355. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/ser/fmt.rs +0 -0
  356. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/ser/impls.rs +0 -0
  357. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/ser/impossible.rs +0 -0
  358. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/ser/mod.rs +0 -0
  359. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/core/std_error.rs +0 -0
  360. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/integer128.rs +0 -0
  361. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/private/de.rs +0 -0
  362. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/private/mod.rs +0 -0
  363. /data/ext/cargo-vendor/{serde-1.0.228 → serde-1.0.229}/src/private/ser.rs +0 -0
  364. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/LICENSE-APACHE +0 -0
  365. /data/ext/cargo-vendor/{serde-1.0.228 → serde_core-1.0.229}/LICENSE-MIT +0 -0
  366. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/README.md +0 -0
  367. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/crate_root.rs +0 -0
  368. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/de/ignored_any.rs +0 -0
  369. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/de/mod.rs +0 -0
  370. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/de/value.rs +0 -0
  371. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/format.rs +0 -0
  372. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/macros.rs +0 -0
  373. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/private/content.rs +0 -0
  374. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/private/doc.rs +0 -0
  375. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/private/mod.rs +0 -0
  376. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/private/seed.rs +0 -0
  377. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/private/size_hint.rs +0 -0
  378. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/private/string.rs +0 -0
  379. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/ser/fmt.rs +0 -0
  380. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/ser/impls.rs +0 -0
  381. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/ser/impossible.rs +0 -0
  382. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/ser/mod.rs +0 -0
  383. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_core-1.0.229}/src/std_error.rs +0 -0
  384. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/LICENSE-APACHE +0 -0
  385. /data/ext/cargo-vendor/{serde_core-1.0.228 → serde_derive-1.0.229}/LICENSE-MIT +0 -0
  386. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/crates-io.md +0 -0
  387. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/enum_.rs +0 -0
  388. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/enum_internally.rs +0 -0
  389. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/enum_untagged.rs +0 -0
  390. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/identifier.rs +0 -0
  391. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/struct_.rs +0 -0
  392. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/tuple.rs +0 -0
  393. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/de/unit.rs +0 -0
  394. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/deprecated.rs +0 -0
  395. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/dummy.rs +0 -0
  396. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/fragment.rs +0 -0
  397. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/case.rs +0 -0
  398. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/check.rs +0 -0
  399. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/mod.rs +0 -0
  400. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/name.rs +0 -0
  401. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/respan.rs +0 -0
  402. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/internals/symbol.rs +0 -0
  403. /data/ext/cargo-vendor/{serde_derive-1.0.228 → serde_derive-1.0.229}/src/this.rs +0 -0
  404. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/LICENSE +0 -0
  405. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/array_deserializer.rs +0 -0
  406. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/array_enumerator.rs +0 -0
  407. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/enum_deserializer.rs +0 -0
  408. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/hash_deserializer.rs +0 -0
  409. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/mod.rs +0 -0
  410. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/de/variant_deserializer.rs +0 -0
  411. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/error.rs +0 -0
  412. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/lib.rs +0 -0
  413. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/enums.rs +0 -0
  414. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/map_serializer.rs +0 -0
  415. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/mod.rs +0 -0
  416. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/seq_serializer.rs +0 -0
  417. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/serializer.rs +0 -0
  418. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/struct_serializer.rs +0 -0
  419. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/struct_variant_serializer.rs +0 -0
  420. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/src/ser/tuple_variant_serializer.rs +0 -0
  421. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_arrays.rs +0 -0
  422. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_booleans.rs +0 -0
  423. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_enums.rs +0 -0
  424. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_floats.rs +0 -0
  425. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_integers.rs +0 -0
  426. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_maps.rs +0 -0
  427. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_options.rs +0 -0
  428. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_results.rs +0 -0
  429. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_strings.rs +0 -0
  430. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_structs.rs +0 -0
  431. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_tuples.rs +0 -0
  432. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/deserializing_vecs.rs +0 -0
  433. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_arrays.rs +0 -0
  434. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_booleans.rs +0 -0
  435. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_enums.rs +0 -0
  436. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_floats.rs +0 -0
  437. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_integers.rs +0 -0
  438. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_maps.rs +0 -0
  439. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_options.rs +0 -0
  440. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_results.rs +0 -0
  441. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_strings.rs +0 -0
  442. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_structs.rs +0 -0
  443. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_tuples.rs +0 -0
  444. /data/ext/cargo-vendor/{serde_magnus-0.10.0 → serde_magnus-0.11.0}/tests/serializing_vecs.rs +0 -0
  445. /data/ext/cargo-vendor/{serde_derive-1.0.228 → syn-3.0.9}/LICENSE-MIT +0 -0
@@ -20,7 +20,10 @@ use self::struct_layout::StructLayoutTracker;
20
20
 
21
21
  use super::BindgenOptions;
22
22
 
23
- use crate::callbacks::{DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind};
23
+ use crate::callbacks::{
24
+ AttributeInfo, DeriveInfo, DiscoveredItem, DiscoveredItemId, FieldInfo,
25
+ TypeKind as DeriveTypeKind,
26
+ };
24
27
  use crate::codegen::error::Error;
25
28
  use crate::ir::analysis::{HasVtable, Sizedness};
26
29
  use crate::ir::annotations::{
@@ -52,8 +55,8 @@ use crate::ir::template::{
52
55
  use crate::ir::ty::{Type, TypeKind};
53
56
  use crate::ir::var::Var;
54
57
 
55
- use proc_macro2::{self, Ident, Span};
56
- use quote::TokenStreamExt;
58
+ use proc_macro2::{Ident, Span};
59
+ use quote::{ToTokens, TokenStreamExt};
57
60
 
58
61
  use crate::{Entry, HashMap, HashSet};
59
62
  use std::borrow::Cow;
@@ -80,7 +83,7 @@ impl fmt::Display for CodegenError {
80
83
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81
84
  match self {
82
85
  Self::Serialize { msg, loc } => {
83
- write!(f, "serialization error at {}: {}", loc, msg)
86
+ write!(f, "serialization error at {loc}: {msg}")
84
87
  }
85
88
  Self::Io(err) => err.fmt(f),
86
89
  }
@@ -149,22 +152,16 @@ fn derives_of_item(
149
152
  ) -> DerivableTraits {
150
153
  let mut derivable_traits = DerivableTraits::empty();
151
154
 
152
- let all_template_params = item.all_template_params(ctx);
153
-
154
155
  if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() {
155
156
  derivable_traits |= DerivableTraits::COPY;
156
157
 
157
- if ctx.options().rust_features().builtin_clone_impls ||
158
- !all_template_params.is_empty()
159
- {
160
- // FIXME: This requires extra logic if you have a big array in a
161
- // templated struct. The reason for this is that the magic:
162
- // fn clone(&self) -> Self { *self }
163
- // doesn't work for templates.
164
- //
165
- // It's not hard to fix though.
166
- derivable_traits |= DerivableTraits::CLONE;
167
- }
158
+ // FIXME: This requires extra logic if you have a big array in a
159
+ // templated struct. The reason for this is that the magic:
160
+ // fn clone(&self) -> Self { *self }
161
+ // doesn't work for templates.
162
+ //
163
+ // It's not hard to fix though.
164
+ derivable_traits |= DerivableTraits::CLONE;
168
165
  } else if packed {
169
166
  // If the struct or union is packed, deriving from Copy is required for
170
167
  // deriving from any other trait.
@@ -376,7 +373,7 @@ impl<'a> CodegenResult<'a> {
376
373
  }
377
374
  }
378
375
 
379
- impl<'a> ops::Deref for CodegenResult<'a> {
376
+ impl ops::Deref for CodegenResult<'_> {
380
377
  type Target = Vec<proc_macro2::TokenStream>;
381
378
 
382
379
  fn deref(&self) -> &Self::Target {
@@ -384,7 +381,7 @@ impl<'a> ops::Deref for CodegenResult<'a> {
384
381
  }
385
382
  }
386
383
 
387
- impl<'a> ops::DerefMut for CodegenResult<'a> {
384
+ impl ops::DerefMut for CodegenResult<'_> {
388
385
  fn deref_mut(&mut self) -> &mut Self::Target {
389
386
  &mut self.items
390
387
  }
@@ -507,7 +504,7 @@ impl Item {
507
504
  // TODO(emilio, #453): Figure out what to do when this happens
508
505
  // legitimately, we could track the opaque stuff and disable the
509
506
  // assertion there I guess.
510
- warn!("Found non-allowlisted item in code generation: {:?}", self);
507
+ warn!("Found non-allowlisted item in code generation: {self:?}");
511
508
  }
512
509
 
513
510
  result.set_seen(self.id());
@@ -525,7 +522,7 @@ impl CodeGenerator for Item {
525
522
  result: &mut CodegenResult<'_>,
526
523
  _extra: &(),
527
524
  ) {
528
- debug!("<Item as CodeGenerator>::codegen: self = {:?}", self);
525
+ debug!("<Item as CodeGenerator>::codegen: self = {self:?}");
529
526
  if !self.process_before_codegen(ctx, result) {
530
527
  return;
531
528
  }
@@ -557,7 +554,7 @@ impl CodeGenerator for Module {
557
554
  result: &mut CodegenResult<'_>,
558
555
  item: &Item,
559
556
  ) {
560
- debug!("<Module as CodeGenerator>::codegen: item = {:?}", item);
557
+ debug!("<Module as CodeGenerator>::codegen: item = {item:?}");
561
558
 
562
559
  let codegen_self = |result: &mut CodegenResult,
563
560
  found_any: &mut bool| {
@@ -584,6 +581,9 @@ impl CodeGenerator for Module {
584
581
  if ctx.need_bindgen_complex_type() {
585
582
  utils::prepend_complex_type(&mut *result);
586
583
  }
584
+ if ctx.need_opaque_array_type() {
585
+ utils::prepend_opaque_array_type(&mut *result);
586
+ }
587
587
  if result.saw_objc {
588
588
  utils::prepend_objc_header(ctx, &mut *result);
589
589
  }
@@ -656,7 +656,7 @@ impl CodeGenerator for Var {
656
656
  item: &Item,
657
657
  ) {
658
658
  use crate::ir::var::VarType;
659
- debug!("<Var as CodeGenerator>::codegen: item = {:?}", item);
659
+ debug!("<Var as CodeGenerator>::codegen: item = {item:?}");
660
660
  debug_assert!(item.is_enabled_for_codegen(ctx));
661
661
 
662
662
  let canonical_name = item.canonical_name(ctx);
@@ -677,7 +677,7 @@ impl CodeGenerator for Var {
677
677
 
678
678
  let mut attrs = vec![];
679
679
  if let Some(comment) = item.comment(ctx) {
680
- attrs.push(attributes::doc(comment));
680
+ attrs.push(attributes::doc(&comment));
681
681
  }
682
682
 
683
683
  let var_ty = self.ty();
@@ -721,33 +721,41 @@ impl CodeGenerator for Var {
721
721
  let len = proc_macro2::Literal::usize_unsuffixed(
722
722
  cstr_bytes.len(),
723
723
  );
724
-
725
- // TODO: Here we ignore the type we just made up, probably
726
- // we should refactor how the variable type and ty ID work.
727
- let array_ty = quote! { [u8; #len] };
728
- let cstr_ty = quote! { ::#prefix::ffi::CStr };
729
-
730
- let bytes = proc_macro2::Literal::byte_string(&cstr_bytes);
731
-
732
- if options.generate_cstr &&
733
- rust_features.const_cstr &&
734
- CStr::from_bytes_with_nul(&cstr_bytes).is_ok()
735
- {
736
- result.push(quote! {
737
- #(#attrs)*
738
- #[allow(unsafe_code)]
739
- pub const #canonical_ident: &#cstr_ty = unsafe {
740
- #cstr_ty::from_bytes_with_nul_unchecked(#bytes)
741
- };
742
- });
743
- } else {
744
- let lifetime = if rust_features.static_lifetime_elision
745
- {
724
+ let cstr =
725
+ if options.generate_cstr && rust_features.const_cstr {
726
+ CStr::from_bytes_with_nul(&cstr_bytes).ok()
727
+ } else {
746
728
  None
729
+ };
730
+
731
+ if let Some(cstr) = cstr {
732
+ let cstr_ty = quote! { ::#prefix::ffi::CStr };
733
+ if rust_features.literal_cstr {
734
+ let cstr = proc_macro2::Literal::c_string(cstr);
735
+ result.push(quote! {
736
+ #(#attrs)*
737
+ pub const #canonical_ident: &#cstr_ty = #cstr;
738
+ });
747
739
  } else {
748
- Some(quote! { 'static })
740
+ let bytes =
741
+ proc_macro2::Literal::byte_string(&cstr_bytes);
742
+ result.push(quote! {
743
+ #(#attrs)*
744
+ #[allow(unsafe_code)]
745
+ pub const #canonical_ident: &#cstr_ty = unsafe {
746
+ #cstr_ty::from_bytes_with_nul_unchecked(#bytes)
747
+ };
748
+ });
749
749
  }
750
- .into_iter();
750
+ } else {
751
+ // TODO: Here we ignore the type we just made up, probably
752
+ // we should refactor how the variable type and ty ID work.
753
+ let array_ty = quote! { [u8; #len] };
754
+ let bytes =
755
+ proc_macro2::Literal::byte_string(&cstr_bytes);
756
+ let lifetime =
757
+ if true { None } else { Some(quote! { 'static }) }
758
+ .into_iter();
751
759
 
752
760
  result.push(quote! {
753
761
  #(#attrs)*
@@ -771,20 +779,20 @@ impl CodeGenerator for Var {
771
779
  }
772
780
  }
773
781
  } else {
774
- // If necessary, apply a `#[link_name]` attribute
775
- if let Some(link_name) = self.link_name() {
776
- attrs.push(attributes::link_name::<false>(link_name));
777
- } else {
782
+ let symbol: &str = self.link_name().unwrap_or_else(|| {
778
783
  let link_name =
779
784
  self.mangled_name().unwrap_or_else(|| self.name());
780
- if !utils::names_will_be_identical_after_mangling(
785
+ if utils::names_will_be_identical_after_mangling(
781
786
  &canonical_name,
782
787
  link_name,
783
788
  None,
784
789
  ) {
790
+ canonical_name.as_str()
791
+ } else {
785
792
  attrs.push(attributes::link_name::<false>(link_name));
793
+ link_name
786
794
  }
787
- }
795
+ });
788
796
 
789
797
  let maybe_mut = if self.is_const() {
790
798
  quote! {}
@@ -792,14 +800,33 @@ impl CodeGenerator for Var {
792
800
  quote! { mut }
793
801
  };
794
802
 
803
+ let safety = ctx
804
+ .options()
805
+ .rust_features
806
+ .unsafe_extern_blocks
807
+ .then(|| quote!(unsafe));
808
+
795
809
  let tokens = quote!(
796
- extern "C" {
810
+ #safety extern "C" {
797
811
  #(#attrs)*
798
812
  pub static #maybe_mut #canonical_ident: #ty;
799
813
  }
800
814
  );
801
815
 
802
- result.push(tokens);
816
+ if ctx.options().dynamic_library_name.is_some() {
817
+ result.dynamic_items().push_var(
818
+ &canonical_ident,
819
+ symbol,
820
+ &self
821
+ .ty()
822
+ .to_rust_ty_or_opaque(ctx, &())
823
+ .into_token_stream(),
824
+ ctx.options().dynamic_link_require_all,
825
+ ctx.options().wrap_unsafe_ops,
826
+ );
827
+ } else {
828
+ result.push(tokens);
829
+ }
803
830
  }
804
831
  }
805
832
  }
@@ -814,7 +841,7 @@ impl CodeGenerator for Type {
814
841
  result: &mut CodegenResult<'_>,
815
842
  item: &Item,
816
843
  ) {
817
- debug!("<Type as CodeGenerator>::codegen: item = {:?}", item);
844
+ debug!("<Type as CodeGenerator>::codegen: item = {item:?}");
818
845
  debug_assert!(item.is_enabled_for_codegen(ctx));
819
846
 
820
847
  match *self.kind() {
@@ -837,7 +864,7 @@ impl CodeGenerator for Type {
837
864
  // it to BindgenContext::compute_allowlisted_and_codegen_items.
838
865
  }
839
866
  TypeKind::TemplateInstantiation(ref inst) => {
840
- inst.codegen(ctx, result, item)
867
+ inst.codegen(ctx, result, item);
841
868
  }
842
869
  TypeKind::BlockPointer(inner) => {
843
870
  if !ctx.options().generate_block {
@@ -854,14 +881,14 @@ impl CodeGenerator for Type {
854
881
  {
855
882
  utils::fnsig_block(ctx, fnsig)
856
883
  } else {
857
- panic!("invalid block typedef: {:?}", inner_item)
884
+ panic!("invalid block typedef: {inner_item:?}")
858
885
  }
859
886
  };
860
887
 
861
888
  let rust_name = ctx.rust_ident(name);
862
889
 
863
890
  let mut tokens = if let Some(comment) = item.comment(ctx) {
864
- attributes::doc(comment)
891
+ attributes::doc(&comment)
865
892
  } else {
866
893
  quote! {}
867
894
  };
@@ -912,16 +939,14 @@ impl CodeGenerator for Type {
912
939
  assert_eq!(
913
940
  layout.size,
914
941
  ctx.target_pointer_size(),
915
- "Target platform requires `--no-size_t-is-usize`. The size of `{}` ({}) does not match the target pointer size ({})",
916
- spelling,
942
+ "Target platform requires `--no-size_t-is-usize`. The size of `{spelling}` ({}) does not match the target pointer size ({})",
917
943
  layout.size,
918
944
  ctx.target_pointer_size(),
919
945
  );
920
946
  assert_eq!(
921
947
  layout.align,
922
948
  ctx.target_pointer_size(),
923
- "Target platform requires `--no-size_t-is-usize`. The alignment of `{}` ({}) does not match the target pointer size ({})",
924
- spelling,
949
+ "Target platform requires `--no-size_t-is-usize`. The alignment of `{spelling}` ({}) does not match the target pointer size ({})",
925
950
  layout.align,
926
951
  ctx.target_pointer_size(),
927
952
  );
@@ -970,8 +995,20 @@ impl CodeGenerator for Type {
970
995
 
971
996
  let rust_name = ctx.rust_ident(&name);
972
997
 
998
+ ctx.options().for_each_callback(|cb| {
999
+ cb.new_item_found(
1000
+ DiscoveredItemId::new(item.id().as_usize()),
1001
+ DiscoveredItem::Alias {
1002
+ alias_name: rust_name.to_string(),
1003
+ alias_for: DiscoveredItemId::new(
1004
+ inner_item.id().as_usize(),
1005
+ ),
1006
+ },
1007
+ );
1008
+ });
1009
+
973
1010
  let mut tokens = if let Some(comment) = item.comment(ctx) {
974
- attributes::doc(comment)
1011
+ attributes::doc(&comment)
975
1012
  } else {
976
1013
  quote! {}
977
1014
  };
@@ -1011,21 +1048,38 @@ impl CodeGenerator for Type {
1011
1048
  pub type #rust_name
1012
1049
  },
1013
1050
  AliasVariation::NewType | AliasVariation::NewTypeDeref => {
1014
- assert!(
1015
- ctx.options().rust_features().repr_transparent,
1016
- "repr_transparent feature is required to use {:?}",
1017
- alias_style
1018
- );
1019
-
1020
1051
  let mut attributes =
1021
1052
  vec![attributes::repr("transparent")];
1022
1053
  let packed = false; // Types can't be packed in Rust.
1023
1054
  let derivable_traits =
1024
1055
  derives_of_item(item, ctx, packed);
1025
- if !derivable_traits.is_empty() {
1026
- let derives: Vec<_> = derivable_traits.into();
1027
- attributes.push(attributes::derives(&derives))
1028
- }
1056
+ let mut derives: Vec<_> = derivable_traits.into();
1057
+ // The custom derives callback may return a list of derive attributes;
1058
+ // add them to the end of the list.
1059
+ let custom_derives =
1060
+ ctx.options().all_callbacks(|cb| {
1061
+ cb.add_derives(&DeriveInfo {
1062
+ name: &name,
1063
+ kind: DeriveTypeKind::Struct,
1064
+ })
1065
+ });
1066
+ // In most cases this will be a no-op, since custom_derives will be empty.
1067
+ derives
1068
+ .extend(custom_derives.iter().map(|s| s.as_str()));
1069
+ attributes.push(attributes::derives(&derives));
1070
+
1071
+ let custom_attributes =
1072
+ ctx.options().all_callbacks(|cb| {
1073
+ cb.add_attributes(&AttributeInfo {
1074
+ name: &name,
1075
+ kind: DeriveTypeKind::Struct,
1076
+ })
1077
+ });
1078
+ attributes.extend(
1079
+ custom_attributes
1080
+ .iter()
1081
+ .map(|s| s.parse().unwrap()),
1082
+ );
1029
1083
 
1030
1084
  quote! {
1031
1085
  #( #attributes )*
@@ -1064,13 +1118,24 @@ impl CodeGenerator for Type {
1064
1118
  });
1065
1119
  }
1066
1120
 
1067
- let access_spec =
1068
- access_specifier(ctx.options().default_visibility);
1069
1121
  tokens.append_all(match alias_style {
1070
1122
  AliasVariation::TypeAlias => quote! {
1071
1123
  = #inner_rust_type ;
1072
1124
  },
1073
1125
  AliasVariation::NewType | AliasVariation::NewTypeDeref => {
1126
+ let visibility = ctx
1127
+ .options()
1128
+ .last_callback(|cb| {
1129
+ cb.field_visibility(FieldInfo {
1130
+ type_name: &item.canonical_name(ctx),
1131
+ field_name: "0",
1132
+ field_type_name: inner_item
1133
+ .expect_type()
1134
+ .name(),
1135
+ })
1136
+ })
1137
+ .unwrap_or(ctx.options().default_visibility);
1138
+ let access_spec = access_specifier(visibility);
1074
1139
  quote! {
1075
1140
  (#access_spec #inner_rust_type) ;
1076
1141
  }
@@ -1103,10 +1168,10 @@ impl CodeGenerator for Type {
1103
1168
  result.saw_objc();
1104
1169
  }
1105
1170
  TypeKind::ObjCInterface(ref interface) => {
1106
- interface.codegen(ctx, result, item)
1171
+ interface.codegen(ctx, result, item);
1107
1172
  }
1108
1173
  ref u @ TypeKind::UnresolvedTypeRef(..) => {
1109
- unreachable!("Should have been resolved after parsing {:?}!", u)
1174
+ unreachable!("Should have been resolved after parsing {u:?}!")
1110
1175
  }
1111
1176
  }
1112
1177
  }
@@ -1125,7 +1190,7 @@ impl<'a> Vtable<'a> {
1125
1190
  }
1126
1191
  }
1127
1192
 
1128
- impl<'a> CodeGenerator for Vtable<'a> {
1193
+ impl CodeGenerator for Vtable<'_> {
1129
1194
  type Extra = Item;
1130
1195
  type Return = ();
1131
1196
 
@@ -1160,10 +1225,7 @@ impl<'a> CodeGenerator for Vtable<'a> {
1160
1225
  let function_item = ctx.resolve_item(m.signature());
1161
1226
  let function = function_item.expect_function();
1162
1227
  let signature_item = ctx.resolve_item(function.signature());
1163
- let signature = match signature_item.expect_type().kind() {
1164
- TypeKind::Function(ref sig) => sig,
1165
- _ => panic!("Function signature type mismatch"),
1166
- };
1228
+ let TypeKind::Function(ref signature) = signature_item.expect_type().kind() else { panic!("Function signature type mismatch") };
1167
1229
 
1168
1230
  // FIXME: Is there a canonical name without the class prepended?
1169
1231
  let function_name = function_item.canonical_name(ctx);
@@ -1190,7 +1252,7 @@ impl<'a> CodeGenerator for Vtable<'a> {
1190
1252
  pub struct #name {
1191
1253
  #( #methods ),*
1192
1254
  }
1193
- })
1255
+ });
1194
1256
  } else {
1195
1257
  // For the cases we don't support, simply generate an empty struct.
1196
1258
  let void = helpers::ast_ty::c_void(ctx);
@@ -1203,13 +1265,13 @@ impl<'a> CodeGenerator for Vtable<'a> {
1203
1265
  }
1204
1266
  }
1205
1267
 
1206
- impl<'a> ItemCanonicalName for Vtable<'a> {
1268
+ impl ItemCanonicalName for Vtable<'_> {
1207
1269
  fn canonical_name(&self, ctx: &BindgenContext) -> String {
1208
1270
  format!("{}__bindgen_vtable", self.item_id.canonical_name(ctx))
1209
1271
  }
1210
1272
  }
1211
1273
 
1212
- impl<'a> TryToRustTy for Vtable<'a> {
1274
+ impl TryToRustTy for Vtable<'_> {
1213
1275
  type Extra = ();
1214
1276
 
1215
1277
  fn try_to_rust_ty(
@@ -1244,6 +1306,9 @@ impl CodeGenerator for TemplateInstantiation {
1244
1306
  return;
1245
1307
  }
1246
1308
 
1309
+ // For consistency with other layout tests, gate this on offset_of.
1310
+ let compile_time = ctx.options().rust_features().offset_of;
1311
+
1247
1312
  // If there are any unbound type parameters, then we can't generate a
1248
1313
  // layout test because we aren't dealing with a concrete type with a
1249
1314
  // concrete size and alignment.
@@ -1258,14 +1323,17 @@ impl CodeGenerator for TemplateInstantiation {
1258
1323
  let align = layout.align;
1259
1324
 
1260
1325
  let name = item.full_disambiguated_name(ctx);
1261
- let mut fn_name =
1262
- format!("__bindgen_test_layout_{}_instantiation", name);
1263
- let times_seen = result.overload_number(&fn_name);
1264
- if times_seen > 0 {
1265
- write!(&mut fn_name, "_{}", times_seen).unwrap();
1266
- }
1267
-
1268
- let fn_name = ctx.rust_ident_raw(fn_name);
1326
+ let fn_name = if compile_time {
1327
+ None
1328
+ } else {
1329
+ let mut fn_name =
1330
+ format!("__bindgen_test_layout_{name}_instantiation");
1331
+ let times_seen = result.overload_number(&fn_name);
1332
+ if times_seen > 0 {
1333
+ write!(&mut fn_name, "_{times_seen}").unwrap();
1334
+ }
1335
+ Some(ctx.rust_ident_raw(fn_name))
1336
+ };
1269
1337
 
1270
1338
  let prefix = ctx.trait_prefix();
1271
1339
  let ident = item.to_rust_ty_or_opaque(ctx, &());
@@ -1275,20 +1343,33 @@ impl CodeGenerator for TemplateInstantiation {
1275
1343
  let align_of_expr = quote! {
1276
1344
  ::#prefix::mem::align_of::<#ident>()
1277
1345
  };
1278
-
1279
- let item = quote! {
1280
- #[test]
1281
- fn #fn_name() {
1282
- assert_eq!(#size_of_expr, #size,
1283
- concat!("Size of template specialization: ",
1284
- stringify!(#ident)));
1285
- assert_eq!(#align_of_expr, #align,
1286
- concat!("Alignment of template specialization: ",
1287
- stringify!(#ident)));
1288
- }
1289
- };
1290
-
1291
- result.push(item);
1346
+ let size_of_err =
1347
+ format!("Size of template specialization: {name}");
1348
+ let align_of_err =
1349
+ format!("Align of template specialization: {name}");
1350
+
1351
+ if compile_time {
1352
+ // In an ideal world this would be assert_eq!, but that is not
1353
+ // supported in const fn due to the need for string formatting.
1354
+ // If #size_of_expr > #size, this will index OOB, and if
1355
+ // #size_of_expr < #size, the subtraction will overflow, both
1356
+ // of which print enough information to see what has gone wrong.
1357
+ result.push(quote! {
1358
+ #[allow(clippy::unnecessary_operation, clippy::identity_op)]
1359
+ const _: () = {
1360
+ [#size_of_err][#size_of_expr - #size];
1361
+ [#align_of_err][#align_of_expr - #align];
1362
+ };
1363
+ });
1364
+ } else {
1365
+ result.push(quote! {
1366
+ #[test]
1367
+ fn #fn_name() {
1368
+ assert_eq!(#size_of_expr, #size, #size_of_err);
1369
+ assert_eq!(#align_of_expr, #align, #align_of_err);
1370
+ }
1371
+ });
1372
+ }
1292
1373
  }
1293
1374
  }
1294
1375
  }
@@ -1305,6 +1386,7 @@ trait FieldCodegen<'a> {
1305
1386
  accessor_kind: FieldAccessorKind,
1306
1387
  parent: &CompInfo,
1307
1388
  parent_item: &Item,
1389
+ last_field: bool,
1308
1390
  result: &mut CodegenResult,
1309
1391
  struct_layout: &mut StructLayoutTracker,
1310
1392
  fields: &mut F,
@@ -1315,7 +1397,7 @@ trait FieldCodegen<'a> {
1315
1397
  M: Extend<proc_macro2::TokenStream>;
1316
1398
  }
1317
1399
 
1318
- impl<'a> FieldCodegen<'a> for Field {
1400
+ impl FieldCodegen<'_> for Field {
1319
1401
  type Extra = ();
1320
1402
 
1321
1403
  fn codegen<F, M>(
@@ -1325,6 +1407,7 @@ impl<'a> FieldCodegen<'a> for Field {
1325
1407
  accessor_kind: FieldAccessorKind,
1326
1408
  parent: &CompInfo,
1327
1409
  parent_item: &Item,
1410
+ last_field: bool,
1328
1411
  result: &mut CodegenResult,
1329
1412
  struct_layout: &mut StructLayoutTracker,
1330
1413
  fields: &mut F,
@@ -1342,6 +1425,7 @@ impl<'a> FieldCodegen<'a> for Field {
1342
1425
  accessor_kind,
1343
1426
  parent,
1344
1427
  parent_item,
1428
+ last_field,
1345
1429
  result,
1346
1430
  struct_layout,
1347
1431
  fields,
@@ -1356,6 +1440,7 @@ impl<'a> FieldCodegen<'a> for Field {
1356
1440
  accessor_kind,
1357
1441
  parent,
1358
1442
  parent_item,
1443
+ last_field,
1359
1444
  result,
1360
1445
  struct_layout,
1361
1446
  fields,
@@ -1390,7 +1475,7 @@ fn wrap_union_field_if_needed(
1390
1475
  }
1391
1476
  }
1392
1477
 
1393
- impl<'a> FieldCodegen<'a> for FieldData {
1478
+ impl FieldCodegen<'_> for FieldData {
1394
1479
  type Extra = ();
1395
1480
 
1396
1481
  fn codegen<F, M>(
@@ -1400,6 +1485,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
1400
1485
  accessor_kind: FieldAccessorKind,
1401
1486
  parent: &CompInfo,
1402
1487
  parent_item: &Item,
1488
+ last_field: bool,
1403
1489
  result: &mut CodegenResult,
1404
1490
  struct_layout: &mut StructLayoutTracker,
1405
1491
  fields: &mut F,
@@ -1425,14 +1511,20 @@ impl<'a> FieldCodegen<'a> for FieldData {
1425
1511
  let ty = if parent.is_union() {
1426
1512
  wrap_union_field_if_needed(ctx, struct_layout, ty, result)
1427
1513
  } else if let Some(item) = field_ty.is_incomplete_array(ctx) {
1428
- result.saw_incomplete_array();
1514
+ // Only FAM if its the last field
1515
+ if ctx.options().flexarray_dst && last_field {
1516
+ struct_layout.saw_flexible_array();
1517
+ syn::parse_quote! { FAM }
1518
+ } else {
1519
+ result.saw_incomplete_array();
1429
1520
 
1430
- let inner = item.to_rust_ty_or_opaque(ctx, &());
1521
+ let inner = item.to_rust_ty_or_opaque(ctx, &());
1431
1522
 
1432
- if ctx.options().enable_cxx_namespaces {
1433
- syn::parse_quote! { root::__IncompleteArrayField<#inner> }
1434
- } else {
1435
- syn::parse_quote! { __IncompleteArrayField<#inner> }
1523
+ if ctx.options().enable_cxx_namespaces {
1524
+ syn::parse_quote! { root::__IncompleteArrayField<#inner> }
1525
+ } else {
1526
+ syn::parse_quote! { __IncompleteArrayField<#inner> }
1527
+ }
1436
1528
  }
1437
1529
  } else {
1438
1530
  ty
@@ -1442,7 +1534,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
1442
1534
  if ctx.options().generate_comments {
1443
1535
  if let Some(raw_comment) = self.comment() {
1444
1536
  let comment = ctx.options().process_comment(raw_comment);
1445
- field = attributes::doc(comment);
1537
+ field = attributes::doc(&comment);
1446
1538
  }
1447
1539
  }
1448
1540
 
@@ -1466,6 +1558,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
1466
1558
  cb.field_visibility(FieldInfo {
1467
1559
  type_name: &parent_item.canonical_name(ctx),
1468
1560
  field_name,
1561
+ field_type_name: field_ty.name(),
1469
1562
  })
1470
1563
  }),
1471
1564
  self.annotations(),
@@ -1499,9 +1592,9 @@ impl<'a> FieldCodegen<'a> for FieldData {
1499
1592
  return;
1500
1593
  }
1501
1594
 
1502
- let getter_name = ctx.rust_ident_raw(format!("get_{}", field_name));
1595
+ let getter_name = ctx.rust_ident_raw(format!("get_{field_name}"));
1503
1596
  let mutable_getter_name =
1504
- ctx.rust_ident_raw(format!("get_{}_mut", field_name));
1597
+ ctx.rust_ident_raw(format!("get_{field_name}_mut"));
1505
1598
 
1506
1599
  methods.extend(Some(match accessor_kind {
1507
1600
  FieldAccessorKind::None => unreachable!(),
@@ -1563,18 +1656,17 @@ impl Bitfield {
1563
1656
  fn extend_ctor_impl(
1564
1657
  &self,
1565
1658
  ctx: &BindgenContext,
1566
- param_name: proc_macro2::TokenStream,
1659
+ param_name: &proc_macro2::TokenStream,
1567
1660
  mut ctor_impl: proc_macro2::TokenStream,
1568
1661
  ) -> proc_macro2::TokenStream {
1569
1662
  let bitfield_ty = ctx.resolve_type(self.ty());
1570
1663
  let bitfield_ty_layout = bitfield_ty
1571
1664
  .layout(ctx)
1572
1665
  .expect("Bitfield without layout? Gah!");
1573
- let bitfield_int_ty = helpers::integer_type(ctx, bitfield_ty_layout)
1574
- .expect(
1575
- "Should already have verified that the bitfield is \
1666
+ let bitfield_int_ty = helpers::integer_type(bitfield_ty_layout).expect(
1667
+ "Should already have verified that the bitfield is \
1576
1668
  representable as an int",
1577
- );
1669
+ );
1578
1670
 
1579
1671
  let offset = self.offset_into_unit();
1580
1672
  let width = self.width() as u8;
@@ -1609,13 +1701,13 @@ fn access_specifier(
1609
1701
 
1610
1702
  /// Compute a fields or structs visibility based on multiple conditions.
1611
1703
  /// 1. If the element was declared public, and we respect such CXX accesses specs
1612
- /// (context option) => By default Public, but this can be overruled by an `annotation`.
1704
+ /// (context option) => By default Public, but this can be overruled by an `annotation`.
1613
1705
  ///
1614
1706
  /// 2. If the element was declared private, and we respect such CXX accesses specs
1615
- /// (context option) => By default Private, but this can be overruled by an `annotation`.
1707
+ /// (context option) => By default Private, but this can be overruled by an `annotation`.
1616
1708
  ///
1617
1709
  /// 3. If we do not respect visibility modifiers, the result depends on the `annotation`,
1618
- /// if any, or the passed `default_kind`.
1710
+ /// if any, or the passed `default_kind`.
1619
1711
  ///
1620
1712
  fn compute_visibility(
1621
1713
  ctx: &BindgenContext,
@@ -1644,7 +1736,7 @@ fn compute_visibility(
1644
1736
  })
1645
1737
  }
1646
1738
 
1647
- impl<'a> FieldCodegen<'a> for BitfieldUnit {
1739
+ impl FieldCodegen<'_> for BitfieldUnit {
1648
1740
  type Extra = ();
1649
1741
 
1650
1742
  fn codegen<F, M>(
@@ -1654,6 +1746,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
1654
1746
  accessor_kind: FieldAccessorKind,
1655
1747
  parent: &CompInfo,
1656
1748
  parent_item: &Item,
1749
+ last_field: bool,
1657
1750
  result: &mut CodegenResult,
1658
1751
  struct_layout: &mut StructLayoutTracker,
1659
1752
  fields: &mut F,
@@ -1714,7 +1807,8 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
1714
1807
  let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT;
1715
1808
 
1716
1809
  let mut unit_visibility = visibility_kind;
1717
- for bf in self.bitfields() {
1810
+ let bfields = self.bitfields();
1811
+ for (idx, bf) in bfields.iter().enumerate() {
1718
1812
  // Codegen not allowed for anonymous bitfields
1719
1813
  if bf.name().is_none() {
1720
1814
  continue;
@@ -1734,12 +1828,14 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
1734
1828
  accessor_kind,
1735
1829
  parent,
1736
1830
  parent_item,
1831
+ last_field && idx == bfields.len() - 1,
1737
1832
  result,
1738
1833
  struct_layout,
1739
1834
  fields,
1740
1835
  methods,
1741
1836
  (
1742
1837
  &unit_field_name,
1838
+ &unit_field_ty,
1743
1839
  &mut bitfield_representable_as_int,
1744
1840
  &mut bitfield_visibility,
1745
1841
  ),
@@ -1763,7 +1859,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
1763
1859
  ctor_params.push(quote! {
1764
1860
  #param_name : #bitfield_ty
1765
1861
  });
1766
- ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl);
1862
+ ctor_impl = bf.extend_ctor_impl(ctx, &param_name, ctor_impl);
1767
1863
  }
1768
1864
 
1769
1865
  let access_spec = access_specifier(unit_visibility);
@@ -1797,6 +1893,15 @@ fn bitfield_getter_name(
1797
1893
  quote! { #name }
1798
1894
  }
1799
1895
 
1896
+ fn bitfield_raw_getter_name(
1897
+ ctx: &BindgenContext,
1898
+ bitfield: &Bitfield,
1899
+ ) -> proc_macro2::TokenStream {
1900
+ let name = bitfield.getter_name();
1901
+ let name = ctx.rust_ident_raw(format!("{name}_raw"));
1902
+ quote! { #name }
1903
+ }
1904
+
1800
1905
  fn bitfield_setter_name(
1801
1906
  ctx: &BindgenContext,
1802
1907
  bitfield: &Bitfield,
@@ -1806,8 +1911,22 @@ fn bitfield_setter_name(
1806
1911
  quote! { #setter }
1807
1912
  }
1808
1913
 
1914
+ fn bitfield_raw_setter_name(
1915
+ ctx: &BindgenContext,
1916
+ bitfield: &Bitfield,
1917
+ ) -> proc_macro2::TokenStream {
1918
+ let setter = bitfield.setter_name();
1919
+ let setter = ctx.rust_ident_raw(format!("{setter}_raw"));
1920
+ quote! { #setter }
1921
+ }
1922
+
1809
1923
  impl<'a> FieldCodegen<'a> for Bitfield {
1810
- type Extra = (&'a str, &'a mut bool, &'a mut FieldVisibilityKind);
1924
+ type Extra = (
1925
+ &'a str,
1926
+ &'a syn::Type,
1927
+ &'a mut bool,
1928
+ &'a mut FieldVisibilityKind,
1929
+ );
1811
1930
 
1812
1931
  fn codegen<F, M>(
1813
1932
  &self,
@@ -1816,12 +1935,19 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1816
1935
  _accessor_kind: FieldAccessorKind,
1817
1936
  parent: &CompInfo,
1818
1937
  parent_item: &Item,
1938
+ _last_field: bool,
1819
1939
  _result: &mut CodegenResult,
1820
1940
  struct_layout: &mut StructLayoutTracker,
1821
1941
  _fields: &mut F,
1822
1942
  methods: &mut M,
1823
- (unit_field_name, bitfield_representable_as_int, bitfield_visibility): (
1943
+ (
1944
+ unit_field_name,
1945
+ unit_field_ty,
1946
+ bitfield_representable_as_int,
1947
+ bitfield_visibility,
1948
+ ): (
1824
1949
  &'a str,
1950
+ &'a syn::Type,
1825
1951
  &mut bool,
1826
1952
  &'a mut FieldVisibilityKind,
1827
1953
  ),
@@ -1832,24 +1958,24 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1832
1958
  let prefix = ctx.trait_prefix();
1833
1959
  let getter_name = bitfield_getter_name(ctx, self);
1834
1960
  let setter_name = bitfield_setter_name(ctx, self);
1961
+ let raw_getter_name = bitfield_raw_getter_name(ctx, self);
1962
+ let raw_setter_name = bitfield_raw_setter_name(ctx, self);
1835
1963
  let unit_field_ident = Ident::new(unit_field_name, Span::call_site());
1836
1964
 
1837
1965
  let bitfield_ty_item = ctx.resolve_item(self.ty());
1838
1966
  let bitfield_ty = bitfield_ty_item.expect_type();
1967
+ let bitfield_ty_ident = bitfield_ty.name();
1839
1968
 
1840
1969
  let bitfield_ty_layout = bitfield_ty
1841
1970
  .layout(ctx)
1842
1971
  .expect("Bitfield without layout? Gah!");
1843
1972
  let bitfield_int_ty =
1844
- match helpers::integer_type(ctx, bitfield_ty_layout) {
1845
- Some(int_ty) => {
1846
- *bitfield_representable_as_int = true;
1847
- int_ty
1848
- }
1849
- None => {
1850
- *bitfield_representable_as_int = false;
1851
- return;
1852
- }
1973
+ if let Some(int_ty) = helpers::integer_type(bitfield_ty_layout) {
1974
+ *bitfield_representable_as_int = true;
1975
+ int_ty
1976
+ } else {
1977
+ *bitfield_representable_as_int = false;
1978
+ return;
1853
1979
  };
1854
1980
 
1855
1981
  let bitfield_ty =
@@ -1863,6 +1989,7 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1863
1989
  cb.field_visibility(FieldInfo {
1864
1990
  type_name: &parent_item.canonical_name(ctx),
1865
1991
  field_name,
1992
+ field_type_name: bitfield_ty_ident,
1866
1993
  })
1867
1994
  })
1868
1995
  });
@@ -1899,6 +2026,34 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1899
2026
  }
1900
2027
  }
1901
2028
  }));
2029
+
2030
+ if ctx.options().rust_features.raw_ref_macros {
2031
+ methods.extend(Some(quote! {
2032
+ #[inline]
2033
+ #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty {
2034
+ unsafe {
2035
+ ::#prefix::mem::transmute(<#unit_field_ty>::raw_get(
2036
+ (*::#prefix::ptr::addr_of!((*this).#unit_field_ident)).as_ref() as *const _,
2037
+ #offset,
2038
+ #width,
2039
+ ) as #bitfield_int_ty)
2040
+ }
2041
+ }
2042
+
2043
+ #[inline]
2044
+ #access_spec unsafe fn #raw_setter_name(this: *mut Self, val: #bitfield_ty) {
2045
+ unsafe {
2046
+ let val: #bitfield_int_ty = ::#prefix::mem::transmute(val);
2047
+ <#unit_field_ty>::raw_set(
2048
+ (*::#prefix::ptr::addr_of_mut!((*this).#unit_field_ident)).as_mut() as *mut _,
2049
+ #offset,
2050
+ #width,
2051
+ val as u64,
2052
+ )
2053
+ }
2054
+ }
2055
+ }));
2056
+ }
1902
2057
  } else {
1903
2058
  methods.extend(Some(quote! {
1904
2059
  #[inline]
@@ -1923,6 +2078,34 @@ impl<'a> FieldCodegen<'a> for Bitfield {
1923
2078
  }
1924
2079
  }
1925
2080
  }));
2081
+
2082
+ if ctx.options().rust_features.raw_ref_macros {
2083
+ methods.extend(Some(quote! {
2084
+ #[inline]
2085
+ #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty {
2086
+ unsafe {
2087
+ ::#prefix::mem::transmute(<#unit_field_ty>::raw_get(
2088
+ ::#prefix::ptr::addr_of!((*this).#unit_field_ident),
2089
+ #offset,
2090
+ #width,
2091
+ ) as #bitfield_int_ty)
2092
+ }
2093
+ }
2094
+
2095
+ #[inline]
2096
+ #access_spec unsafe fn #raw_setter_name(this: *mut Self, val: #bitfield_ty) {
2097
+ unsafe {
2098
+ let val: #bitfield_int_ty = ::#prefix::mem::transmute(val);
2099
+ <#unit_field_ty>::raw_set(
2100
+ ::#prefix::ptr::addr_of_mut!((*this).#unit_field_ident),
2101
+ #offset,
2102
+ #width,
2103
+ val as u64,
2104
+ )
2105
+ }
2106
+ }
2107
+ }));
2108
+ }
1926
2109
  }
1927
2110
  }
1928
2111
  }
@@ -1937,7 +2120,7 @@ impl CodeGenerator for CompInfo {
1937
2120
  result: &mut CodegenResult<'_>,
1938
2121
  item: &Item,
1939
2122
  ) {
1940
- debug!("<CompInfo as CodeGenerator>::codegen: item = {:?}", item);
2123
+ debug!("<CompInfo as CodeGenerator>::codegen: item = {item:?}");
1941
2124
  debug_assert!(item.is_enabled_for_codegen(ctx));
1942
2125
 
1943
2126
  // Don't output classes with template parameters that aren't types, and
@@ -1980,6 +2163,23 @@ impl CodeGenerator for CompInfo {
1980
2163
  packed,
1981
2164
  );
1982
2165
 
2166
+ let mut generic_param_names = vec![];
2167
+
2168
+ for (idx, ty) in item.used_template_params(ctx).iter().enumerate() {
2169
+ let param = ctx.resolve_type(*ty);
2170
+ let name = param.name().unwrap();
2171
+ let ident = ctx.rust_ident(name);
2172
+ generic_param_names.push(ident.clone());
2173
+
2174
+ let prefix = ctx.trait_prefix();
2175
+ let field_name = ctx.rust_ident(format!("_phantom_{idx}"));
2176
+ fields.push(quote! {
2177
+ pub #field_name : ::#prefix::marker::PhantomData<
2178
+ ::#prefix::cell::UnsafeCell<#ident>
2179
+ > ,
2180
+ });
2181
+ }
2182
+
1983
2183
  if !is_opaque {
1984
2184
  if item.has_vtable_ptr(ctx) {
1985
2185
  let vtable = Vtable::new(item.id(), self);
@@ -2032,13 +2232,15 @@ impl CodeGenerator for CompInfo {
2032
2232
  .annotations()
2033
2233
  .accessor_kind()
2034
2234
  .unwrap_or(FieldAccessorKind::None);
2035
- for field in self.fields() {
2235
+ let field_decls = self.fields();
2236
+ for (idx, field) in field_decls.iter().enumerate() {
2036
2237
  field.codegen(
2037
2238
  ctx,
2038
2239
  visibility,
2039
2240
  struct_accessor_kind,
2040
2241
  self,
2041
2242
  item,
2243
+ idx == field_decls.len() - 1,
2042
2244
  result,
2043
2245
  &mut struct_layout,
2044
2246
  &mut fields,
@@ -2090,7 +2292,7 @@ impl CodeGenerator for CompInfo {
2090
2292
 
2091
2293
  if has_address {
2092
2294
  let layout = Layout::new(1, 1);
2093
- let ty = helpers::blob(ctx, Layout::new(1, 1));
2295
+ let ty = helpers::blob(ctx, Layout::new(1, 1), false);
2094
2296
  struct_layout.saw_field_with_layout(
2095
2297
  "_address",
2096
2298
  layout,
@@ -2107,13 +2309,15 @@ impl CodeGenerator for CompInfo {
2107
2309
  Some(l) => {
2108
2310
  explicit_align = Some(l.align);
2109
2311
 
2110
- let ty = helpers::blob(ctx, l);
2312
+ let ty = helpers::blob(ctx, l, false);
2111
2313
  fields.push(quote! {
2112
2314
  pub _bindgen_opaque_blob: #ty ,
2113
2315
  });
2114
2316
  }
2115
2317
  None => {
2116
- warn!("Opaque type without layout! Expect dragons!");
2318
+ if !forward_decl {
2319
+ warn!("Opaque type without layout! Expect dragons!");
2320
+ }
2117
2321
  }
2118
2322
  }
2119
2323
  } else if !is_union && !zero_sized {
@@ -2129,31 +2333,21 @@ impl CodeGenerator for CompInfo {
2129
2333
  packed = true;
2130
2334
  } else {
2131
2335
  explicit_align = Some(layout.align);
2132
- if !ctx.options().rust_features.repr_align {
2133
- let ty = helpers::blob(
2134
- ctx,
2135
- Layout::new(0, layout.align),
2136
- );
2137
- fields.push(quote! {
2138
- pub __bindgen_align: #ty ,
2139
- });
2140
- }
2141
2336
  }
2142
2337
  }
2143
2338
  }
2144
2339
  } else if is_union && !forward_decl {
2145
- // TODO(emilio): It'd be nice to unify this with the struct path
2146
- // above somehow.
2147
- let layout = layout.expect("Unable to get layout information?");
2148
- if struct_layout.requires_explicit_align(layout) {
2149
- explicit_align = Some(layout.align);
2150
- }
2151
-
2152
- if !struct_layout.is_rust_union() {
2153
- let ty = helpers::blob(ctx, layout);
2154
- fields.push(quote! {
2155
- pub bindgen_union_field: #ty ,
2156
- })
2340
+ if let Some(layout) = layout {
2341
+ // TODO(emilio): It'd be nice to unify this with the struct path above somehow.
2342
+ if struct_layout.requires_explicit_align(layout) {
2343
+ explicit_align = Some(layout.align);
2344
+ }
2345
+ if !struct_layout.is_rust_union() {
2346
+ let ty = helpers::blob(ctx, layout, false);
2347
+ fields.push(quote! {
2348
+ pub bindgen_union_field: #ty ,
2349
+ });
2350
+ }
2157
2351
  }
2158
2352
  }
2159
2353
 
@@ -2163,39 +2357,62 @@ impl CodeGenerator for CompInfo {
2163
2357
  });
2164
2358
  }
2165
2359
 
2166
- let mut generic_param_names = vec![];
2167
-
2168
- for (idx, ty) in item.used_template_params(ctx).iter().enumerate() {
2169
- let param = ctx.resolve_type(*ty);
2170
- let name = param.name().unwrap();
2171
- let ident = ctx.rust_ident(name);
2172
- generic_param_names.push(ident.clone());
2173
-
2174
- let prefix = ctx.trait_prefix();
2175
- let field_name = ctx.rust_ident(format!("_phantom_{}", idx));
2176
- fields.push(quote! {
2177
- pub #field_name : ::#prefix::marker::PhantomData<
2178
- ::#prefix::cell::UnsafeCell<#ident>
2179
- > ,
2180
- });
2181
- }
2182
-
2183
- let generics = if !generic_param_names.is_empty() {
2184
- let generic_param_names = generic_param_names.clone();
2185
- quote! {
2186
- < #( #generic_param_names ),* >
2360
+ let (flex_array_generic, flex_inner_ty) = if ctx.options().flexarray_dst
2361
+ {
2362
+ match self.flex_array_member(ctx) {
2363
+ Some(ty) => {
2364
+ let inner = ty.to_rust_ty_or_opaque(ctx, &());
2365
+ (
2366
+ Some(quote! { FAM: ?Sized = [ #inner; 0 ] }),
2367
+ Some(quote! { #inner }),
2368
+ )
2369
+ }
2370
+ None => (None, None),
2187
2371
  }
2188
2372
  } else {
2189
- quote! {}
2373
+ (None, None)
2190
2374
  };
2191
2375
 
2376
+ // Generics, including the flexible array member.
2377
+ //
2378
+ // generics - generic parameters for the struct declaration
2379
+ // impl_generics_labels - generic parameters for `impl<...>`
2380
+ // impl_generics_params - generic parameters for `impl structname<...>`
2381
+ //
2382
+ // `impl` blocks are for non-FAM related impls like Default, etc
2383
+ let (generics, impl_generics_labels, impl_generics_params) =
2384
+ if !generic_param_names.is_empty() || flex_array_generic.is_some() {
2385
+ let (flex_sized, flex_fam) = match flex_inner_ty.as_ref() {
2386
+ None => (None, None),
2387
+ Some(ty) => (
2388
+ Some(quote! { [ #ty; 0 ] }),
2389
+ Some(quote! { FAM: ?Sized = [ #ty; 0 ] }),
2390
+ ),
2391
+ };
2392
+
2393
+ (
2394
+ quote! {
2395
+ < #( #generic_param_names , )* #flex_fam >
2396
+ },
2397
+ quote! {
2398
+ < #( #generic_param_names , )* >
2399
+ },
2400
+ quote! {
2401
+ < #( #generic_param_names , )* #flex_sized >
2402
+ },
2403
+ )
2404
+ } else {
2405
+ (quote! {}, quote! {}, quote! {})
2406
+ };
2407
+
2192
2408
  let mut attributes = vec![];
2193
2409
  let mut needs_clone_impl = false;
2194
2410
  let mut needs_default_impl = false;
2195
2411
  let mut needs_debug_impl = false;
2196
2412
  let mut needs_partialeq_impl = false;
2413
+ let needs_flexarray_impl = flex_array_generic.is_some();
2197
2414
  if let Some(comment) = item.comment(ctx) {
2198
- attributes.push(attributes::doc(comment));
2415
+ attributes.push(attributes::doc(&comment));
2199
2416
  }
2200
2417
 
2201
2418
  // if a type has both a "packed" attribute and an "align(N)" attribute, then check if the
@@ -2210,14 +2427,14 @@ impl CodeGenerator for CompInfo {
2210
2427
  let packed_repr = if n == 1 {
2211
2428
  "packed".to_string()
2212
2429
  } else {
2213
- format!("packed({})", n)
2430
+ format!("packed({n})")
2214
2431
  };
2215
2432
  attributes.push(attributes::repr_list(&["C", &packed_repr]));
2216
2433
  } else {
2217
2434
  attributes.push(attributes::repr("C"));
2218
2435
  }
2219
2436
 
2220
- if ctx.options().rust_features().repr_align {
2437
+ if true {
2221
2438
  if let Some(explicit) = explicit_align {
2222
2439
  // Ensure that the struct has the correct alignment even in
2223
2440
  // presence of alignas.
@@ -2263,6 +2480,30 @@ impl CodeGenerator for CompInfo {
2263
2480
 
2264
2481
  let is_rust_union = is_union && struct_layout.is_rust_union();
2265
2482
 
2483
+ let discovered_id = DiscoveredItemId::new(item.id().as_usize());
2484
+ ctx.options().for_each_callback(|cb| {
2485
+ let discovered_item = match self.kind() {
2486
+ CompKind::Struct => DiscoveredItem::Struct {
2487
+ original_name: item
2488
+ .kind()
2489
+ .expect_type()
2490
+ .name()
2491
+ .map(String::from),
2492
+ final_name: canonical_ident.to_string(),
2493
+ },
2494
+ CompKind::Union => DiscoveredItem::Union {
2495
+ original_name: item
2496
+ .kind()
2497
+ .expect_type()
2498
+ .name()
2499
+ .map(String::from),
2500
+ final_name: canonical_ident.to_string(),
2501
+ },
2502
+ };
2503
+
2504
+ cb.new_item_found(discovered_id, discovered_item);
2505
+ });
2506
+
2266
2507
  // The custom derives callback may return a list of derive attributes;
2267
2508
  // add them to the end of the list.
2268
2509
  let custom_derives = ctx.options().all_callbacks(|cb| {
@@ -2279,9 +2520,28 @@ impl CodeGenerator for CompInfo {
2279
2520
  derives.extend(custom_derives.iter().map(|s| s.as_str()));
2280
2521
 
2281
2522
  if !derives.is_empty() {
2282
- attributes.push(attributes::derives(&derives))
2523
+ attributes.push(attributes::derives(&derives));
2283
2524
  }
2284
2525
 
2526
+ attributes.extend(
2527
+ item.annotations()
2528
+ .attributes()
2529
+ .iter()
2530
+ .map(|s| s.parse().unwrap()),
2531
+ );
2532
+
2533
+ let custom_attributes = ctx.options().all_callbacks(|cb| {
2534
+ cb.add_attributes(&AttributeInfo {
2535
+ name: &canonical_name,
2536
+ kind: if is_rust_union {
2537
+ DeriveTypeKind::Union
2538
+ } else {
2539
+ DeriveTypeKind::Struct
2540
+ },
2541
+ })
2542
+ });
2543
+ attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
2544
+
2285
2545
  if item.must_use(ctx) {
2286
2546
  attributes.push(attributes::must_use());
2287
2547
  }
@@ -2319,10 +2579,7 @@ impl CodeGenerator for CompInfo {
2319
2579
  // affect layout, so we're bad and pray to the gods for avoid sending
2320
2580
  // all the tests to shit when parsing things like max_align_t.
2321
2581
  if self.found_unknown_attr() {
2322
- warn!(
2323
- "Type {} has an unknown attribute that may affect layout",
2324
- canonical_ident
2325
- );
2582
+ warn!("Type {canonical_ident} has an unknown attribute that may affect layout");
2326
2583
  }
2327
2584
 
2328
2585
  if all_template_params.is_empty() {
@@ -2334,9 +2591,14 @@ impl CodeGenerator for CompInfo {
2334
2591
 
2335
2592
  if ctx.options().layout_tests && !self.is_forward_declaration() {
2336
2593
  if let Some(layout) = layout {
2337
- let fn_name =
2338
- format!("bindgen_test_layout_{}", canonical_ident);
2339
- let fn_name = ctx.rust_ident_raw(fn_name);
2594
+ let compile_time = ctx.options().rust_features().offset_of;
2595
+ let fn_name = if compile_time {
2596
+ None
2597
+ } else {
2598
+ let fn_name =
2599
+ format!("bindgen_test_layout_{canonical_ident}");
2600
+ Some(ctx.rust_ident_raw(fn_name))
2601
+ };
2340
2602
  let prefix = ctx.trait_prefix();
2341
2603
  let size_of_expr = quote! {
2342
2604
  ::#prefix::mem::size_of::<#canonical_ident>()
@@ -2346,19 +2608,18 @@ impl CodeGenerator for CompInfo {
2346
2608
  };
2347
2609
  let size = layout.size;
2348
2610
  let align = layout.align;
2611
+ let size_of_err = format!("Size of {canonical_ident}");
2612
+ let align_of_err =
2613
+ format!("Alignment of {canonical_ident}");
2349
2614
 
2350
- let check_struct_align = if align >
2351
- ctx.target_pointer_size() &&
2352
- !ctx.options().rust_features().repr_align
2353
- {
2354
- None
2615
+ let check_struct_align = if compile_time {
2616
+ quote! {
2617
+ [#align_of_err][#align_of_expr - #align];
2618
+ }
2355
2619
  } else {
2356
- Some(quote! {
2357
- assert_eq!(#align_of_expr,
2358
- #align,
2359
- concat!("Alignment of ", stringify!(#canonical_ident)));
2360
-
2361
- })
2620
+ quote! {
2621
+ assert_eq!(#align_of_expr, #align, #align_of_err);
2622
+ }
2362
2623
  };
2363
2624
 
2364
2625
  let should_skip_field_offset_checks = is_opaque;
@@ -2369,30 +2630,40 @@ impl CodeGenerator for CompInfo {
2369
2630
  } else {
2370
2631
  self.fields()
2371
2632
  .iter()
2372
- .filter_map(|field| match *field {
2373
- Field::DataMember(ref f) if f.name().is_some() => Some(f),
2374
- _ => None,
2375
- })
2376
- .flat_map(|field| {
2377
- let name = field.name().unwrap();
2633
+ .filter_map(|field| {
2634
+ let Field::DataMember(field) = field else { return None };
2635
+ let name = field.name()?;
2378
2636
  field.offset().map(|offset| {
2379
2637
  let field_offset = offset / 8;
2380
2638
  let field_name = ctx.rust_ident(name);
2381
- quote! {
2382
- assert_eq!(
2383
- unsafe {
2384
- ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize
2385
- },
2386
- #field_offset,
2387
- concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name))
2388
- );
2639
+ let offset_of_err = format!("Offset of field: {canonical_ident}::{field_name}");
2640
+ if compile_time {
2641
+ quote! {
2642
+ [#offset_of_err][
2643
+ ::#prefix::mem::offset_of!(#canonical_ident, #field_name) - #field_offset
2644
+ ];
2645
+ }
2646
+ } else {
2647
+ quote! {
2648
+ assert_eq!(
2649
+ unsafe {
2650
+ ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize
2651
+ },
2652
+ #field_offset,
2653
+ #offset_of_err
2654
+ );
2655
+ }
2389
2656
  }
2390
2657
  })
2391
2658
  })
2392
2659
  .collect()
2393
2660
  };
2394
2661
 
2395
- let uninit_decl = if !check_field_offset.is_empty() {
2662
+ let uninit_decl = if check_field_offset.is_empty() ||
2663
+ compile_time
2664
+ {
2665
+ None
2666
+ } else {
2396
2667
  // FIXME: When MSRV >= 1.59.0, we can use
2397
2668
  // > const PTR: *const #canonical_ident = ::#prefix::mem::MaybeUninit::uninit().as_ptr();
2398
2669
  Some(quote! {
@@ -2402,35 +2673,42 @@ impl CodeGenerator for CompInfo {
2402
2673
  const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit();
2403
2674
  let ptr = UNINIT.as_ptr();
2404
2675
  })
2405
- } else {
2406
- None
2407
2676
  };
2408
2677
 
2409
- let item = quote! {
2410
- #[test]
2411
- fn #fn_name() {
2412
- #uninit_decl
2413
- assert_eq!(#size_of_expr,
2414
- #size,
2415
- concat!("Size of: ", stringify!(#canonical_ident)));
2416
- #check_struct_align
2417
- #( #check_field_offset )*
2418
- }
2419
- };
2420
- result.push(item);
2678
+ if compile_time {
2679
+ result.push(quote! {
2680
+ #[allow(clippy::unnecessary_operation, clippy::identity_op)]
2681
+ const _: () = {
2682
+ [#size_of_err][#size_of_expr - #size];
2683
+ #check_struct_align
2684
+ #( #check_field_offset )*
2685
+ };
2686
+ });
2687
+ } else {
2688
+ result.push(quote! {
2689
+ #[test]
2690
+ fn #fn_name() {
2691
+ #uninit_decl
2692
+ assert_eq!(#size_of_expr, #size, #size_of_err);
2693
+ #check_struct_align
2694
+ #( #check_field_offset )*
2695
+ }
2696
+ });
2697
+ }
2421
2698
  }
2422
2699
  }
2423
2700
 
2424
2701
  let mut method_names = Default::default();
2425
2702
  if ctx.options().codegen_config.methods() {
2426
2703
  for method in self.methods() {
2427
- assert!(method.kind() != MethodKind::Constructor);
2704
+ assert_ne!(method.kind(), MethodKind::Constructor);
2428
2705
  method.codegen_method(
2429
2706
  ctx,
2430
2707
  &mut methods,
2431
2708
  &mut method_names,
2432
2709
  result,
2433
2710
  self,
2711
+ discovered_id,
2434
2712
  );
2435
2713
  }
2436
2714
  }
@@ -2449,6 +2727,7 @@ impl CodeGenerator for CompInfo {
2449
2727
  &mut method_names,
2450
2728
  result,
2451
2729
  self,
2730
+ discovered_id,
2452
2731
  );
2453
2732
  }
2454
2733
  }
@@ -2462,6 +2741,7 @@ impl CodeGenerator for CompInfo {
2462
2741
  &mut method_names,
2463
2742
  result,
2464
2743
  self,
2744
+ discovered_id,
2465
2745
  );
2466
2746
  }
2467
2747
  }
@@ -2470,17 +2750,27 @@ impl CodeGenerator for CompInfo {
2470
2750
  // NB: We can't use to_rust_ty here since for opaque types this tries to
2471
2751
  // use the specialization knowledge to generate a blob field.
2472
2752
  let ty_for_impl = quote! {
2473
- #canonical_ident #generics
2753
+ #canonical_ident #impl_generics_params
2474
2754
  };
2475
2755
 
2476
2756
  if needs_clone_impl {
2477
2757
  result.push(quote! {
2478
- impl #generics Clone for #ty_for_impl {
2758
+ impl #impl_generics_labels Clone for #ty_for_impl {
2479
2759
  fn clone(&self) -> Self { *self }
2480
2760
  }
2481
2761
  });
2482
2762
  }
2483
2763
 
2764
+ if needs_flexarray_impl {
2765
+ result.push(self.generate_flexarray(
2766
+ ctx,
2767
+ &canonical_ident,
2768
+ flex_inner_ty.as_ref(),
2769
+ &generic_param_names,
2770
+ &impl_generics_labels,
2771
+ ));
2772
+ }
2773
+
2484
2774
  if needs_default_impl {
2485
2775
  let prefix = ctx.trait_prefix();
2486
2776
  let body = if ctx.options().rust_features().maybe_uninit {
@@ -2502,10 +2792,10 @@ impl CodeGenerator for CompInfo {
2502
2792
  };
2503
2793
  // Note we use `ptr::write_bytes()` instead of `mem::zeroed()` because the latter does
2504
2794
  // not necessarily ensure padding bytes are zeroed. Some C libraries are sensitive to
2505
- // non-zero padding bytes, especially when forwards/backwards compatability is
2795
+ // non-zero padding bytes, especially when forwards/backwards compatibility is
2506
2796
  // involved.
2507
2797
  result.push(quote! {
2508
- impl #generics Default for #ty_for_impl {
2798
+ impl #impl_generics_labels Default for #ty_for_impl {
2509
2799
  fn default() -> Self {
2510
2800
  #body
2511
2801
  }
@@ -2524,7 +2814,7 @@ impl CodeGenerator for CompInfo {
2524
2814
  let prefix = ctx.trait_prefix();
2525
2815
 
2526
2816
  result.push(quote! {
2527
- impl #generics ::#prefix::fmt::Debug for #ty_for_impl {
2817
+ impl #impl_generics_labels ::#prefix::fmt::Debug for #ty_for_impl {
2528
2818
  #impl_
2529
2819
  }
2530
2820
  });
@@ -2537,30 +2827,166 @@ impl CodeGenerator for CompInfo {
2537
2827
  item,
2538
2828
  &ty_for_impl,
2539
2829
  ) {
2540
- let partialeq_bounds = if !generic_param_names.is_empty() {
2830
+ let partialeq_bounds = if generic_param_names.is_empty() {
2831
+ quote! {}
2832
+ } else {
2541
2833
  let bounds = generic_param_names.iter().map(|t| {
2542
2834
  quote! { #t: PartialEq }
2543
2835
  });
2544
2836
  quote! { where #( #bounds ),* }
2545
- } else {
2546
- quote! {}
2547
2837
  };
2548
2838
 
2549
2839
  let prefix = ctx.trait_prefix();
2550
2840
  result.push(quote! {
2551
- impl #generics ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds {
2841
+ impl #impl_generics_labels ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds {
2552
2842
  #impl_
2553
2843
  }
2554
2844
  });
2555
2845
  }
2556
- }
2846
+ }
2847
+
2848
+ if !methods.is_empty() {
2849
+ result.push(quote! {
2850
+ impl #impl_generics_labels #ty_for_impl {
2851
+ #( #methods )*
2852
+ }
2853
+ });
2854
+ }
2855
+ }
2856
+ }
2857
+
2858
+ impl CompInfo {
2859
+ fn generate_flexarray(
2860
+ &self,
2861
+ ctx: &BindgenContext,
2862
+ canonical_ident: &Ident,
2863
+ flex_inner_ty: Option<&proc_macro2::TokenStream>,
2864
+ generic_param_names: &[Ident],
2865
+ impl_generics_labels: &proc_macro2::TokenStream,
2866
+ ) -> proc_macro2::TokenStream {
2867
+ let prefix = ctx.trait_prefix();
2868
+
2869
+ let flex_array = flex_inner_ty.as_ref().map(|ty| quote! { [ #ty ] });
2870
+
2871
+ let dst_ty_for_impl = quote! {
2872
+ #canonical_ident < #( #generic_param_names , )* #flex_array >
2873
+
2874
+ };
2875
+ let sized_ty_for_impl = quote! {
2876
+ #canonical_ident < #( #generic_param_names , )* [ #flex_inner_ty; 0 ] >
2877
+ };
2878
+
2879
+ let layout = if ctx.options().rust_features().layout_for_ptr {
2880
+ quote! {
2881
+ pub fn layout(len: usize) -> ::#prefix::alloc::Layout {
2882
+ // SAFETY: Null pointers are OK if we don't deref them
2883
+ unsafe {
2884
+ let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null::<()>(), len);
2885
+ ::#prefix::alloc::Layout::for_value_raw(p)
2886
+ }
2887
+ }
2888
+ }
2889
+ } else {
2890
+ quote!()
2891
+ };
2892
+
2893
+ let (from_ptr_dst, from_ptr_sized) = if ctx
2894
+ .options()
2895
+ .rust_features()
2896
+ .ptr_metadata
2897
+ {
2898
+ let flex_ref_inner = ctx.wrap_unsafe_ops(quote! {
2899
+ Self::flex_ptr(self, len)
2900
+ });
2901
+ let flex_ref_mut_inner = ctx.wrap_unsafe_ops(quote! {
2902
+ Self::flex_ptr_mut(self, len).assume_init()
2903
+ });
2904
+ let flex_ptr_inner = ctx.wrap_unsafe_ops(quote! {
2905
+ &*::#prefix::ptr::from_raw_parts(ptr as *const (), len)
2906
+ });
2907
+ let flex_ptr_mut_inner = ctx.wrap_unsafe_ops(quote! {
2908
+ // Initialize reference without ever exposing it, as its possibly uninitialized
2909
+ let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit();
2910
+ (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl)
2911
+ .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len));
2912
+
2913
+ uninit
2914
+ });
2915
+
2916
+ (
2917
+ quote! {
2918
+ #[inline]
2919
+ pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) {
2920
+ unsafe {
2921
+ let (ptr, len) = (self as *const Self).to_raw_parts();
2922
+ (&*(ptr as *const #sized_ty_for_impl), len)
2923
+ }
2924
+ }
2925
+
2926
+ #[inline]
2927
+ pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) {
2928
+ unsafe {
2929
+ let (ptr, len) = (self as *mut Self).to_raw_parts();
2930
+ (&mut *(ptr as *mut #sized_ty_for_impl), len)
2931
+ }
2932
+ }
2933
+ },
2934
+ quote! {
2935
+ /// Convert a sized prefix to an unsized structure with the given length.
2936
+ ///
2937
+ /// SAFETY: Underlying storage is initialized up to at least `len` elements.
2938
+ pub unsafe fn flex_ref(&self, len: usize) -> &#dst_ty_for_impl {
2939
+ // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`.
2940
+ #flex_ref_inner
2941
+ }
2942
+
2943
+ /// Convert a mutable sized prefix to an unsized structure with the given length.
2944
+ ///
2945
+ /// SAFETY: Underlying storage is initialized up to at least `len` elements.
2946
+ #[inline]
2947
+ pub unsafe fn flex_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl {
2948
+ // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`.
2949
+ #flex_ref_mut_inner
2950
+ }
2951
+
2952
+ /// Construct DST variant from a pointer and a size.
2953
+ ///
2954
+ /// NOTE: lifetime of returned reference is not tied to any underlying storage.
2955
+ /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements.
2956
+ #[inline]
2957
+ pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl {
2958
+ #flex_ptr_inner
2959
+ }
2960
+
2961
+ /// Construct mutable DST variant from a pointer and a
2962
+ /// size. The returned `&mut` reference is initialized
2963
+ /// pointing to memory referenced by `ptr`, but there's
2964
+ /// no requirement that that memory be initialized.
2965
+ ///
2966
+ /// NOTE: lifetime of returned reference is not tied to any underlying storage.
2967
+ /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements.
2968
+ #[inline]
2969
+ pub unsafe fn flex_ptr_mut<'unbounded>(
2970
+ ptr: *mut Self,
2971
+ len: usize,
2972
+ ) -> ::#prefix::mem::MaybeUninit<&'unbounded mut #dst_ty_for_impl> {
2973
+ #flex_ptr_mut_inner
2974
+ }
2975
+ },
2976
+ )
2977
+ } else {
2978
+ (quote!(), quote!())
2979
+ };
2980
+
2981
+ quote! {
2982
+ impl #impl_generics_labels #dst_ty_for_impl {
2983
+ #layout
2984
+ #from_ptr_dst
2985
+ }
2557
2986
 
2558
- if !methods.is_empty() {
2559
- result.push(quote! {
2560
- impl #generics #ty_for_impl {
2561
- #( #methods )*
2562
- }
2563
- });
2987
+ impl #impl_generics_labels #sized_ty_for_impl {
2988
+ #from_ptr_sized
2989
+ }
2564
2990
  }
2565
2991
  }
2566
2992
  }
@@ -2573,12 +2999,13 @@ impl Method {
2573
2999
  method_names: &mut HashSet<String>,
2574
3000
  result: &mut CodegenResult<'_>,
2575
3001
  _parent: &CompInfo,
3002
+ parent_id: DiscoveredItemId,
2576
3003
  ) {
2577
3004
  assert!({
2578
3005
  let cc = &ctx.options().codegen_config;
2579
3006
  match self.kind() {
2580
3007
  MethodKind::Constructor => cc.constructors(),
2581
- MethodKind::Destructor => cc.destructors(),
3008
+ MethodKind::Destructor |
2582
3009
  MethodKind::VirtualDestructor { .. } => cc.destructors(),
2583
3010
  MethodKind::Static |
2584
3011
  MethodKind::Normal |
@@ -2593,15 +3020,13 @@ impl Method {
2593
3020
 
2594
3021
  // First of all, output the actual function.
2595
3022
  let function_item = ctx.resolve_item(self.signature());
3023
+ let id = DiscoveredItemId::new(function_item.id().as_usize());
2596
3024
  if !function_item.process_before_codegen(ctx, result) {
2597
3025
  return;
2598
3026
  }
2599
3027
  let function = function_item.expect_function();
2600
3028
  let times_seen = function.codegen(ctx, result, function_item);
2601
- let times_seen = match times_seen {
2602
- Some(seen) => seen,
2603
- None => return,
2604
- };
3029
+ let Some(times_seen) = times_seen else { return };
2605
3030
  let signature_item = ctx.resolve_item(function.signature());
2606
3031
  let mut name = match self.kind() {
2607
3032
  MethodKind::Constructor => "new".into(),
@@ -2609,9 +3034,10 @@ impl Method {
2609
3034
  _ => function.name().to_owned(),
2610
3035
  };
2611
3036
 
2612
- let signature = match *signature_item.expect_type().kind() {
2613
- TypeKind::Function(ref sig) => sig,
2614
- _ => panic!("How in the world?"),
3037
+ let TypeKind::Function(ref signature) =
3038
+ *signature_item.expect_type().kind()
3039
+ else {
3040
+ panic!("How in the world?")
2615
3041
  };
2616
3042
 
2617
3043
  let supported_abi = signature.abi(ctx, Some(&*name)).is_ok();
@@ -2630,7 +3056,7 @@ impl Method {
2630
3056
  let mut new_name;
2631
3057
 
2632
3058
  while {
2633
- new_name = format!("{}{}", name, count);
3059
+ new_name = format!("{name}{count}");
2634
3060
  method_names.contains(&new_name)
2635
3061
  } {
2636
3062
  count += 1;
@@ -2641,9 +3067,19 @@ impl Method {
2641
3067
 
2642
3068
  method_names.insert(name.clone());
2643
3069
 
3070
+ ctx.options().for_each_callback(|cb| {
3071
+ cb.new_item_found(
3072
+ id,
3073
+ DiscoveredItem::Method {
3074
+ parent: parent_id,
3075
+ final_name: name.clone(),
3076
+ },
3077
+ );
3078
+ });
3079
+
2644
3080
  let mut function_name = function_item.canonical_name(ctx);
2645
3081
  if times_seen > 0 {
2646
- write!(&mut function_name, "{}", times_seen).unwrap();
3082
+ write!(&mut function_name, "{times_seen}").unwrap();
2647
3083
  }
2648
3084
  let function_name = ctx.rust_ident(function_name);
2649
3085
  let mut args = utils::fnsig_arguments(ctx, signature);
@@ -2701,7 +3137,7 @@ impl Method {
2701
3137
  exprs[0] = quote! {
2702
3138
  self
2703
3139
  };
2704
- };
3140
+ }
2705
3141
 
2706
3142
  let call = quote! {
2707
3143
  #function_name (#( #exprs ),* )
@@ -2718,16 +3154,14 @@ impl Method {
2718
3154
  quote! {
2719
3155
  __bindgen_tmp
2720
3156
  }
2721
- })
3157
+ });
2722
3158
  }
2723
3159
 
2724
3160
  let block = ctx.wrap_unsafe_ops(quote! ( #( #stmts );*));
2725
3161
 
2726
3162
  let mut attrs = vec![attributes::inline()];
2727
3163
 
2728
- if signature.must_use() &&
2729
- ctx.options().rust_features().must_use_function
2730
- {
3164
+ if signature.must_use() {
2731
3165
  attrs.push(attributes::must_use());
2732
3166
  }
2733
3167
 
@@ -2742,11 +3176,11 @@ impl Method {
2742
3176
  }
2743
3177
 
2744
3178
  /// A helper type that represents different enum variations.
2745
- #[derive(Copy, Clone, PartialEq, Eq, Debug)]
3179
+ #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
2746
3180
  pub enum EnumVariation {
2747
3181
  /// The code for this enum will use a Rust enum. Note that creating this in unsafe code
2748
3182
  /// (including FFI) with an invalid value will invoke undefined behaviour, whether or not
2749
- /// its marked as non_exhaustive.
3183
+ /// its marked as `#[non_exhaustive]`.
2750
3184
  Rust {
2751
3185
  /// Indicates whether the generated struct should be `#[non_exhaustive]`
2752
3186
  non_exhaustive: bool,
@@ -2759,26 +3193,21 @@ pub enum EnumVariation {
2759
3193
  is_global: bool,
2760
3194
  },
2761
3195
  /// The code for this enum will use consts
3196
+ #[default]
2762
3197
  Consts,
2763
3198
  /// The code for this enum will use a module containing consts
2764
3199
  ModuleConsts,
2765
3200
  }
2766
3201
 
2767
3202
  impl EnumVariation {
2768
- fn is_rust(&self) -> bool {
2769
- matches!(*self, EnumVariation::Rust { .. })
3203
+ fn is_rust(self) -> bool {
3204
+ matches!(self, EnumVariation::Rust { .. })
2770
3205
  }
2771
3206
 
2772
3207
  /// Both the `Const` and `ModuleConsts` variants will cause this to return
2773
3208
  /// true.
2774
- fn is_const(&self) -> bool {
2775
- matches!(*self, EnumVariation::Consts | EnumVariation::ModuleConsts)
2776
- }
2777
- }
2778
-
2779
- impl Default for EnumVariation {
2780
- fn default() -> EnumVariation {
2781
- EnumVariation::Consts
3209
+ fn is_const(self) -> bool {
3210
+ matches!(self, EnumVariation::Consts | EnumVariation::ModuleConsts)
2782
3211
  }
2783
3212
  }
2784
3213
 
@@ -2811,7 +3240,7 @@ impl fmt::Display for EnumVariation {
2811
3240
  }
2812
3241
  }
2813
3242
 
2814
- impl std::str::FromStr for EnumVariation {
3243
+ impl FromStr for EnumVariation {
2815
3244
  type Err = std::io::Error;
2816
3245
 
2817
3246
  /// Create a `EnumVariation` from a string.
@@ -2849,216 +3278,211 @@ impl std::str::FromStr for EnumVariation {
2849
3278
  }
2850
3279
  }
2851
3280
 
3281
+ struct EnumBuilder {
3282
+ /// Type identifier of the enum.
3283
+ ///
3284
+ /// This is the base name, i.e. for `ModuleConst` enums, this does not include the module name.
3285
+ enum_type: Ident,
3286
+ /// Attributes applying to the enum type
3287
+ attrs: Vec<proc_macro2::TokenStream>,
3288
+ /// The representation of the enum, e.g. `u32`.
3289
+ repr: syn::Type,
3290
+ /// The enum kind we are generating
3291
+ kind: EnumBuilderKind,
3292
+ /// A list of all variants this enum has.
3293
+ enum_variants: Vec<EnumVariantInfo>,
3294
+ }
3295
+
2852
3296
  /// A helper type to construct different enum variations.
2853
- enum EnumBuilder<'a> {
3297
+ enum EnumBuilderKind {
2854
3298
  Rust {
2855
- attrs: Vec<proc_macro2::TokenStream>,
2856
- ident: Ident,
2857
- tokens: proc_macro2::TokenStream,
2858
- emitted_any_variants: bool,
3299
+ non_exhaustive: bool,
2859
3300
  },
2860
3301
  NewType {
2861
- canonical_name: &'a str,
2862
- tokens: proc_macro2::TokenStream,
2863
3302
  is_bitfield: bool,
2864
3303
  is_global: bool,
3304
+ /// if the enum is named or not.
3305
+ is_anonymous: bool,
2865
3306
  },
2866
3307
  Consts {
2867
- variants: Vec<proc_macro2::TokenStream>,
3308
+ needs_typedef: bool,
2868
3309
  },
2869
3310
  ModuleConsts {
2870
- module_name: &'a str,
2871
- module_items: Vec<proc_macro2::TokenStream>,
3311
+ module_name: Ident,
2872
3312
  },
2873
3313
  }
2874
3314
 
2875
- impl<'a> EnumBuilder<'a> {
3315
+ impl EnumBuilder {
2876
3316
  /// Returns true if the builder is for a rustified enum.
2877
3317
  fn is_rust_enum(&self) -> bool {
2878
- matches!(*self, EnumBuilder::Rust { .. })
3318
+ matches!(self.kind, EnumBuilderKind::Rust { .. })
2879
3319
  }
2880
3320
 
2881
3321
  /// Create a new enum given an item builder, a canonical name, a name for
2882
3322
  /// the representation, and which variation it should be generated as.
2883
3323
  fn new(
2884
- name: &'a str,
2885
- mut attrs: Vec<proc_macro2::TokenStream>,
2886
- repr: syn::Type,
3324
+ name: &str,
3325
+ attrs: Vec<proc_macro2::TokenStream>,
3326
+ repr: &syn::Type,
2887
3327
  enum_variation: EnumVariation,
2888
3328
  has_typedef: bool,
3329
+ enum_is_anonymous: bool,
2889
3330
  ) -> Self {
2890
3331
  let ident = Ident::new(name, Span::call_site());
3332
+ // For most variants this is the same
3333
+ let mut enum_ty = ident.clone();
2891
3334
 
2892
- match enum_variation {
3335
+ let kind = match enum_variation {
2893
3336
  EnumVariation::NewType {
2894
3337
  is_bitfield,
2895
3338
  is_global,
2896
- } => EnumBuilder::NewType {
2897
- canonical_name: name,
2898
- tokens: quote! {
2899
- #( #attrs )*
2900
- pub struct #ident (pub #repr);
2901
- },
3339
+ } => EnumBuilderKind::NewType {
2902
3340
  is_bitfield,
2903
3341
  is_global,
3342
+ is_anonymous: enum_is_anonymous,
2904
3343
  },
2905
3344
 
2906
- EnumVariation::Rust { .. } => {
2907
- // `repr` is guaranteed to be Rustified in Enum::codegen
2908
- attrs.insert(0, quote! { #[repr( #repr )] });
2909
- let tokens = quote!();
2910
- EnumBuilder::Rust {
2911
- attrs,
2912
- ident,
2913
- tokens,
2914
- emitted_any_variants: false,
2915
- }
3345
+ EnumVariation::Rust { non_exhaustive } => {
3346
+ EnumBuilderKind::Rust { non_exhaustive }
2916
3347
  }
2917
3348
 
2918
- EnumVariation::Consts => {
2919
- let mut variants = Vec::new();
2920
-
2921
- if !has_typedef {
2922
- variants.push(quote! {
2923
- #( #attrs )*
2924
- pub type #ident = #repr;
2925
- });
2926
- }
2927
-
2928
- EnumBuilder::Consts { variants }
2929
- }
3349
+ EnumVariation::Consts => EnumBuilderKind::Consts {
3350
+ needs_typedef: !has_typedef,
3351
+ },
2930
3352
 
2931
3353
  EnumVariation::ModuleConsts => {
2932
- let ident = Ident::new(
3354
+ enum_ty = Ident::new(
2933
3355
  CONSTIFIED_ENUM_MODULE_REPR_NAME,
2934
3356
  Span::call_site(),
2935
3357
  );
2936
- let type_definition = quote! {
2937
- #( #attrs )*
2938
- pub type #ident = #repr;
2939
- };
2940
3358
 
2941
- EnumBuilder::ModuleConsts {
2942
- module_name: name,
2943
- module_items: vec![type_definition],
3359
+ EnumBuilderKind::ModuleConsts {
3360
+ module_name: ident.clone(),
2944
3361
  }
2945
3362
  }
3363
+ };
3364
+ EnumBuilder {
3365
+ enum_type: enum_ty,
3366
+ attrs,
3367
+ repr: repr.clone(),
3368
+ kind,
3369
+ enum_variants: vec![],
2946
3370
  }
2947
3371
  }
2948
3372
 
2949
3373
  /// Add a variant to this enum.
2950
3374
  fn with_variant(
2951
- self,
3375
+ mut self,
2952
3376
  ctx: &BindgenContext,
2953
3377
  variant: &EnumVariant,
3378
+ variant_doc: proc_macro2::TokenStream,
2954
3379
  mangling_prefix: Option<&str>,
2955
- rust_ty: syn::Type,
2956
- result: &mut CodegenResult<'_>,
3380
+ rust_ty: &syn::Type,
2957
3381
  is_ty_named: bool,
2958
3382
  ) -> Self {
2959
3383
  let variant_name = ctx.rust_mangle(variant.name());
2960
3384
  let is_rust_enum = self.is_rust_enum();
2961
3385
  let expr = match variant.val() {
2962
3386
  EnumVariantValue::Boolean(v) if is_rust_enum => {
2963
- helpers::ast_ty::uint_expr(v as u64)
3387
+ helpers::ast_ty::uint_expr(u64::from(v))
2964
3388
  }
2965
3389
  EnumVariantValue::Boolean(v) => quote!(#v),
2966
3390
  EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v),
2967
3391
  EnumVariantValue::Unsigned(v) => helpers::ast_ty::uint_expr(v),
2968
3392
  };
2969
3393
 
2970
- let mut doc = quote! {};
2971
- if ctx.options().generate_comments {
2972
- if let Some(raw_comment) = variant.comment() {
2973
- let comment = ctx.options().process_comment(raw_comment);
2974
- doc = attributes::doc(comment);
2975
- }
2976
- }
2977
-
2978
- match self {
2979
- EnumBuilder::Rust {
2980
- attrs,
2981
- ident,
2982
- tokens,
2983
- emitted_any_variants: _,
2984
- } => {
3394
+ match self.kind {
3395
+ EnumBuilderKind::Rust { .. } => {
2985
3396
  let name = ctx.rust_ident(variant_name);
2986
- EnumBuilder::Rust {
2987
- attrs,
2988
- ident,
2989
- tokens: quote! {
2990
- #tokens
2991
- #doc
2992
- #name = #expr,
2993
- },
2994
- emitted_any_variants: true,
2995
- }
3397
+ self.enum_variants.push(EnumVariantInfo {
3398
+ variant_name: name,
3399
+ variant_doc,
3400
+ value: expr,
3401
+ });
3402
+ self
2996
3403
  }
2997
3404
 
2998
- EnumBuilder::NewType {
2999
- canonical_name,
3000
- is_global,
3001
- ..
3002
- } => {
3003
- if ctx.options().rust_features().associated_const &&
3004
- is_ty_named &&
3005
- !is_global
3006
- {
3007
- let enum_ident = ctx.rust_ident(canonical_name);
3008
- let variant_ident = ctx.rust_ident(variant_name);
3009
-
3010
- result.push(quote! {
3011
- impl #enum_ident {
3012
- #doc
3013
- pub const #variant_ident : #rust_ty = #rust_ty ( #expr );
3014
- }
3015
- });
3405
+ EnumBuilderKind::NewType { is_global, .. } => {
3406
+ let variant_ident = if is_ty_named && !is_global {
3407
+ ctx.rust_ident(variant_name)
3016
3408
  } else {
3017
- let ident = ctx.rust_ident(match mangling_prefix {
3409
+ ctx.rust_ident(match mangling_prefix {
3018
3410
  Some(prefix) => {
3019
- Cow::Owned(format!("{}_{}", prefix, variant_name))
3411
+ Cow::Owned(format!("{prefix}_{variant_name}"))
3020
3412
  }
3021
3413
  None => variant_name,
3022
- });
3023
- result.push(quote! {
3024
- #doc
3025
- pub const #ident : #rust_ty = #rust_ty ( #expr );
3026
- });
3027
- }
3414
+ })
3415
+ };
3416
+ self.enum_variants.push(EnumVariantInfo {
3417
+ variant_name: variant_ident,
3418
+ variant_doc,
3419
+ value: quote! { #rust_ty ( #expr )},
3420
+ });
3028
3421
 
3029
3422
  self
3030
3423
  }
3031
3424
 
3032
- EnumBuilder::Consts { .. } => {
3425
+ EnumBuilderKind::Consts { .. } => {
3033
3426
  let constant_name = match mangling_prefix {
3034
3427
  Some(prefix) => {
3035
- Cow::Owned(format!("{}_{}", prefix, variant_name))
3428
+ Cow::Owned(format!("{prefix}_{variant_name}"))
3036
3429
  }
3037
3430
  None => variant_name,
3038
3431
  };
3039
3432
 
3040
3433
  let ident = ctx.rust_ident(constant_name);
3041
- result.push(quote! {
3042
- #doc
3043
- pub const #ident : #rust_ty = #expr ;
3434
+ self.enum_variants.push(EnumVariantInfo {
3435
+ variant_name: ident,
3436
+ variant_doc,
3437
+ value: quote! { #expr },
3044
3438
  });
3045
3439
 
3046
3440
  self
3047
3441
  }
3048
- EnumBuilder::ModuleConsts {
3049
- module_name,
3050
- mut module_items,
3051
- } => {
3442
+ EnumBuilderKind::ModuleConsts { .. } => {
3052
3443
  let name = ctx.rust_ident(variant_name);
3053
- let ty = ctx.rust_ident(CONSTIFIED_ENUM_MODULE_REPR_NAME);
3054
- module_items.push(quote! {
3055
- #doc
3056
- pub const #name : #ty = #expr ;
3444
+ self.enum_variants.push(EnumVariantInfo {
3445
+ variant_name: name,
3446
+ variant_doc,
3447
+ value: quote! { #expr },
3057
3448
  });
3449
+ self
3450
+ }
3451
+ }
3452
+ }
3453
+
3454
+ fn newtype_bitfield_impl(
3455
+ prefix: &Ident,
3456
+ rust_ty: &syn::Type,
3457
+ ) -> proc_macro2::TokenStream {
3458
+ let rust_ty_name = &rust_ty;
3459
+ quote! {
3460
+ impl ::#prefix::ops::BitOr<#rust_ty> for #rust_ty {
3461
+ type Output = Self;
3462
+
3463
+ #[inline]
3464
+ fn bitor(self, other: Self) -> Self {
3465
+ #rust_ty_name(self.0 | other.0)
3466
+ }
3467
+ }
3468
+ impl ::#prefix::ops::BitOrAssign for #rust_ty {
3469
+ #[inline]
3470
+ fn bitor_assign(&mut self, rhs: #rust_ty) {
3471
+ self.0 |= rhs.0;
3472
+ }
3473
+ }
3474
+ impl ::#prefix::ops::BitAnd<#rust_ty> for #rust_ty {
3475
+ type Output = Self;
3058
3476
 
3059
- EnumBuilder::ModuleConsts {
3060
- module_name,
3061
- module_items,
3477
+ #[inline]
3478
+ fn bitand(self, other: Self) -> Self {
3479
+ #rust_ty_name(self.0 & other.0)
3480
+ }
3481
+ }
3482
+ impl ::#prefix::ops::BitAndAssign for #rust_ty {
3483
+ #[inline]
3484
+ fn bitand_assign(&mut self, rhs: #rust_ty) {
3485
+ self.0 &= rhs.0;
3062
3486
  }
3063
3487
  }
3064
3488
  }
@@ -3067,95 +3491,142 @@ impl<'a> EnumBuilder<'a> {
3067
3491
  fn build(
3068
3492
  self,
3069
3493
  ctx: &BindgenContext,
3070
- rust_ty: syn::Type,
3071
- result: &mut CodegenResult<'_>,
3494
+ rust_ty: &syn::Type,
3072
3495
  ) -> proc_macro2::TokenStream {
3073
- match self {
3074
- EnumBuilder::Rust {
3075
- attrs,
3076
- ident,
3077
- tokens,
3078
- emitted_any_variants,
3079
- ..
3080
- } => {
3081
- let variants = if !emitted_any_variants {
3082
- quote!(__bindgen_cannot_repr_c_on_empty_enum = 0)
3083
- } else {
3084
- tokens
3085
- };
3496
+ let enum_ident = self.enum_type;
3497
+
3498
+ // 1. Construct a list of the enum variants
3499
+ let variants = match self.kind {
3500
+ EnumBuilderKind::Rust { .. } => {
3501
+ let mut variants = vec![];
3502
+
3503
+ for v in self.enum_variants {
3504
+ let variant_doc = &v.variant_doc;
3505
+ let variant_ident = &v.variant_name;
3506
+ let variant_value = &v.value;
3507
+
3508
+ variants.push(quote! {
3509
+ #variant_doc
3510
+ #variant_ident = #variant_value,
3511
+ });
3512
+ }
3513
+
3514
+ if variants.is_empty() {
3515
+ variants.push(
3516
+ quote! {__bindgen_cannot_repr_c_on_empty_enum = 0,},
3517
+ );
3518
+ }
3519
+ variants
3520
+ }
3521
+ EnumBuilderKind::NewType { .. } => {
3522
+ let mut variants = vec![];
3523
+
3524
+ for v in self.enum_variants {
3525
+ let variant_doc = &v.variant_doc;
3526
+ let variant_ident = &v.variant_name;
3527
+ let variant_value = &v.value;
3528
+
3529
+ variants.push(quote! {
3530
+ #variant_doc
3531
+ pub const #variant_ident: #enum_ident = #variant_value;
3532
+ });
3533
+ }
3534
+ variants
3535
+ }
3536
+ EnumBuilderKind::Consts { .. } |
3537
+ EnumBuilderKind::ModuleConsts { .. } => {
3538
+ let mut variants = vec![];
3539
+
3540
+ for v in self.enum_variants {
3541
+ let variant_doc = &v.variant_doc;
3542
+ let variant_ident = &v.variant_name;
3543
+ let variant_value = &v.value;
3544
+
3545
+ variants.push(quote! {
3546
+ #variant_doc
3547
+ pub const #variant_ident: #enum_ident = #variant_value;
3548
+ });
3549
+ }
3550
+ variants
3551
+ }
3552
+ };
3553
+ let attrs = self.attrs;
3554
+ let enum_repr = &self.repr;
3555
+
3556
+ // 2. Generate the enum representation
3557
+ match self.kind {
3558
+ EnumBuilderKind::Rust { non_exhaustive } => {
3559
+ let non_exhaustive_opt =
3560
+ non_exhaustive.then(attributes::non_exhaustive);
3086
3561
 
3087
3562
  quote! {
3563
+ // Note: repr is on top of attrs to keep the test expectations diff small.
3564
+ // a future commit could move it further down.
3565
+ #[repr(#enum_repr)]
3566
+ #non_exhaustive_opt
3088
3567
  #( #attrs )*
3089
- pub enum #ident {
3090
- #variants
3568
+ pub enum #enum_ident {
3569
+ #( #variants )*
3091
3570
  }
3092
3571
  }
3093
3572
  }
3094
- EnumBuilder::NewType {
3095
- canonical_name,
3096
- tokens,
3573
+ EnumBuilderKind::NewType {
3097
3574
  is_bitfield,
3098
- ..
3575
+ is_global,
3576
+ is_anonymous,
3099
3577
  } => {
3100
- if !is_bitfield {
3101
- return tokens;
3102
- }
3103
-
3104
- let rust_ty_name = ctx.rust_ident_raw(canonical_name);
3105
- let prefix = ctx.trait_prefix();
3106
-
3107
- result.push(quote! {
3108
- impl ::#prefix::ops::BitOr<#rust_ty> for #rust_ty {
3109
- type Output = Self;
3110
-
3111
- #[inline]
3112
- fn bitor(self, other: Self) -> Self {
3113
- #rust_ty_name(self.0 | other.0)
3114
- }
3578
+ // There doesn't seem to be a technical reason why we generate
3579
+ // anon enum variants as global constants.
3580
+ // We keep this behavior to avoid breaking changes in the bindings.
3581
+ let impl_variants = if is_anonymous || is_global {
3582
+ quote! {
3583
+ #( #variants )*
3115
3584
  }
3116
- });
3117
-
3118
- result.push(quote! {
3119
- impl ::#prefix::ops::BitOrAssign for #rust_ty {
3120
- #[inline]
3121
- fn bitor_assign(&mut self, rhs: #rust_ty) {
3122
- self.0 |= rhs.0;
3585
+ } else {
3586
+ quote! {
3587
+ impl #enum_ident {
3588
+ #( #variants )*
3123
3589
  }
3124
3590
  }
3125
- });
3591
+ };
3126
3592
 
3127
- result.push(quote! {
3128
- impl ::#prefix::ops::BitAnd<#rust_ty> for #rust_ty {
3129
- type Output = Self;
3593
+ let prefix = ctx.trait_prefix();
3594
+ let bitfield_impl_opt = is_bitfield
3595
+ .then(|| Self::newtype_bitfield_impl(&prefix, rust_ty));
3130
3596
 
3131
- #[inline]
3132
- fn bitand(self, other: Self) -> Self {
3133
- #rust_ty_name(self.0 & other.0)
3134
- }
3135
- }
3136
- });
3597
+ quote! {
3598
+ // Previously variant impls where before the enum definition.
3599
+ // lets keep this as is for now, to reduce the diff in generated bindings.
3600
+ #impl_variants
3137
3601
 
3138
- result.push(quote! {
3139
- impl ::#prefix::ops::BitAndAssign for #rust_ty {
3140
- #[inline]
3141
- fn bitand_assign(&mut self, rhs: #rust_ty) {
3142
- self.0 &= rhs.0;
3143
- }
3602
+ #bitfield_impl_opt
3603
+
3604
+ #[repr(transparent)]
3605
+ #( #attrs )*
3606
+ pub struct #enum_ident (pub #enum_repr);
3607
+ }
3608
+ }
3609
+ EnumBuilderKind::Consts { needs_typedef } => {
3610
+ let typedef_opt = needs_typedef.then(|| {
3611
+ quote! {
3612
+ #( #attrs )*
3613
+ pub type #enum_ident = #enum_repr;
3144
3614
  }
3145
3615
  });
3616
+ quote! {
3617
+ #( #variants )*
3146
3618
 
3147
- tokens
3619
+ #typedef_opt
3620
+ }
3148
3621
  }
3149
- EnumBuilder::Consts { variants, .. } => quote! { #( #variants )* },
3150
- EnumBuilder::ModuleConsts {
3151
- module_items,
3152
- module_name,
3153
- ..
3154
- } => {
3155
- let ident = ctx.rust_ident(module_name);
3622
+ EnumBuilderKind::ModuleConsts { module_name, .. } => {
3156
3623
  quote! {
3157
- pub mod #ident {
3158
- #( #module_items )*
3624
+ // todo: Probably some attributes, e.g. `cfg` should apply to the `mod`.
3625
+ pub mod #module_name {
3626
+ #( #attrs )*
3627
+ pub type #enum_ident = #enum_repr;
3628
+
3629
+ #( #variants )*
3159
3630
  }
3160
3631
  }
3161
3632
  }
@@ -3173,7 +3644,7 @@ impl CodeGenerator for Enum {
3173
3644
  result: &mut CodegenResult<'_>,
3174
3645
  item: &Item,
3175
3646
  ) {
3176
- debug!("<Enum as CodeGenerator>::codegen: item = {:?}", item);
3647
+ debug!("<Enum as CodeGenerator>::codegen: item = {item:?}");
3177
3648
  debug_assert!(item.is_enabled_for_codegen(ctx));
3178
3649
 
3179
3650
  let name = item.canonical_name(ctx);
@@ -3198,18 +3669,17 @@ impl CodeGenerator for Enum {
3198
3669
  // * the representation couldn't be determined from the C source
3199
3670
  // * it was explicitly requested as a bindgen option
3200
3671
 
3201
- let kind = match repr {
3202
- Some(repr) => match *repr.canonical_type(ctx).kind() {
3672
+ let kind = if let Some(repr) = repr {
3673
+ match *repr.canonical_type(ctx).kind() {
3203
3674
  TypeKind::Int(int_kind) => int_kind,
3204
3675
  _ => panic!("Unexpected type as enum repr"),
3205
- },
3206
- None => {
3207
- warn!(
3208
- "Guessing type of enum! Forward declarations of enums \
3209
- shouldn't be legal!"
3210
- );
3211
- IntKind::Int
3212
3676
  }
3677
+ } else {
3678
+ warn!(
3679
+ "Guessing type of enum! Forward declarations of enums \
3680
+ shouldn't be legal!"
3681
+ );
3682
+ IntKind::Int
3213
3683
  };
3214
3684
 
3215
3685
  let signed = kind.is_signed();
@@ -3229,8 +3699,7 @@ impl CodeGenerator for Enum {
3229
3699
  (false, 8) => IntKind::U64,
3230
3700
  _ => {
3231
3701
  warn!(
3232
- "invalid enum decl: signed: {}, size: {}",
3233
- signed, size
3702
+ "invalid enum decl: signed: {signed}, size: {size}"
3234
3703
  );
3235
3704
  IntKind::I32
3236
3705
  }
@@ -3244,31 +3713,8 @@ impl CodeGenerator for Enum {
3244
3713
 
3245
3714
  let mut attrs = vec![];
3246
3715
 
3247
- // TODO(emilio): Delegate this to the builders?
3248
- match variation {
3249
- EnumVariation::Rust { non_exhaustive } => {
3250
- if non_exhaustive &&
3251
- ctx.options().rust_features().non_exhaustive
3252
- {
3253
- attrs.push(attributes::non_exhaustive());
3254
- } else if non_exhaustive &&
3255
- !ctx.options().rust_features().non_exhaustive
3256
- {
3257
- panic!("The rust target you're using doesn't seem to support non_exhaustive enums");
3258
- }
3259
- }
3260
- EnumVariation::NewType { .. } => {
3261
- if ctx.options().rust_features.repr_transparent {
3262
- attrs.push(attributes::repr("transparent"));
3263
- } else {
3264
- attrs.push(attributes::repr("C"));
3265
- }
3266
- }
3267
- _ => {}
3268
- };
3269
-
3270
3716
  if let Some(comment) = item.comment(ctx) {
3271
- attrs.push(attributes::doc(comment));
3717
+ attrs.push(attributes::doc(&comment));
3272
3718
  }
3273
3719
 
3274
3720
  if item.must_use(ctx) {
@@ -3288,7 +3734,7 @@ impl CodeGenerator for Enum {
3288
3734
  DerivableTraits::EQ,
3289
3735
  );
3290
3736
  let mut derives: Vec<_> = derives.into();
3291
- for derive in item.annotations().derives().iter() {
3737
+ for derive in item.annotations().derives() {
3292
3738
  if !derives.contains(&derive.as_str()) {
3293
3739
  derives.push(derive);
3294
3740
  }
@@ -3305,6 +3751,23 @@ impl CodeGenerator for Enum {
3305
3751
  // In most cases this will be a no-op, since custom_derives will be empty.
3306
3752
  derives.extend(custom_derives.iter().map(|s| s.as_str()));
3307
3753
 
3754
+ attrs.extend(
3755
+ item.annotations()
3756
+ .attributes()
3757
+ .iter()
3758
+ .map(|s| s.parse().unwrap()),
3759
+ );
3760
+
3761
+ // The custom attribute callback may return a list of attributes;
3762
+ // add them to the end of the list.
3763
+ let custom_attributes = ctx.options().all_callbacks(|cb| {
3764
+ cb.add_attributes(&AttributeInfo {
3765
+ name: &name,
3766
+ kind: DeriveTypeKind::Enum,
3767
+ })
3768
+ });
3769
+ attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
3770
+
3308
3771
  attrs.push(attributes::derives(&derives));
3309
3772
  }
3310
3773
 
@@ -3318,17 +3781,17 @@ impl CodeGenerator for Enum {
3318
3781
  // value.
3319
3782
  variant_name: &Ident,
3320
3783
  referenced_name: &Ident,
3321
- enum_rust_ty: syn::Type,
3784
+ enum_rust_ty: &syn::Type,
3322
3785
  result: &mut CodegenResult<'_>,
3323
3786
  ) {
3324
3787
  let constant_name = if enum_.name().is_some() {
3325
3788
  if ctx.options().prepend_enum_name {
3326
- format!("{}_{}", enum_canonical_name, variant_name)
3789
+ format!("{enum_canonical_name}_{variant_name}")
3327
3790
  } else {
3328
- format!("{}", variant_name)
3791
+ format!("{variant_name}")
3329
3792
  }
3330
3793
  } else {
3331
- format!("{}", variant_name)
3794
+ format!("{variant_name}")
3332
3795
  };
3333
3796
  let constant_name = ctx.rust_ident(constant_name);
3334
3797
 
@@ -3341,8 +3804,23 @@ impl CodeGenerator for Enum {
3341
3804
  let repr = repr.to_rust_ty_or_opaque(ctx, item);
3342
3805
  let has_typedef = ctx.is_enum_typedef_combo(item.id());
3343
3806
 
3344
- let mut builder =
3345
- EnumBuilder::new(&name, attrs, repr, variation, has_typedef);
3807
+ ctx.options().for_each_callback(|cb| {
3808
+ cb.new_item_found(
3809
+ DiscoveredItemId::new(item.id().as_usize()),
3810
+ DiscoveredItem::Enum {
3811
+ final_name: name.to_string(),
3812
+ },
3813
+ );
3814
+ });
3815
+
3816
+ let mut builder = EnumBuilder::new(
3817
+ &name,
3818
+ attrs,
3819
+ &repr,
3820
+ variation,
3821
+ has_typedef,
3822
+ enum_ty.name().is_none(),
3823
+ );
3346
3824
 
3347
3825
  // A map where we keep a value -> variant relation.
3348
3826
  let mut seen_values = HashMap::<_, Ident>::default();
@@ -3384,28 +3862,33 @@ impl CodeGenerator for Enum {
3384
3862
  continue;
3385
3863
  }
3386
3864
 
3865
+ let mut variant_doc = quote! {};
3866
+ if ctx.options().generate_comments {
3867
+ if let Some(raw_comment) = variant.comment() {
3868
+ let processed_comment =
3869
+ ctx.options().process_comment(raw_comment);
3870
+ variant_doc = attributes::doc(&processed_comment);
3871
+ }
3872
+ }
3873
+
3387
3874
  match seen_values.entry(variant.val()) {
3388
3875
  Entry::Occupied(ref entry) => {
3389
3876
  if variation.is_rust() {
3390
3877
  let variant_name = ctx.rust_mangle(variant.name());
3391
- let mangled_name =
3392
- if is_toplevel || enum_ty.name().is_some() {
3393
- variant_name
3394
- } else {
3395
- let parent_name =
3396
- parent_canonical_name.as_ref().unwrap();
3878
+ let mangled_name = if is_toplevel ||
3879
+ enum_ty.name().is_some()
3880
+ {
3881
+ variant_name
3882
+ } else {
3883
+ let parent_name =
3884
+ parent_canonical_name.as_ref().unwrap();
3397
3885
 
3398
- Cow::Owned(format!(
3399
- "{}_{}",
3400
- parent_name, variant_name
3401
- ))
3402
- };
3886
+ Cow::Owned(format!("{parent_name}_{variant_name}"))
3887
+ };
3403
3888
 
3404
3889
  let existing_variant_name = entry.get();
3405
3890
  // Use associated constants for named enums.
3406
- if enum_ty.name().is_some() &&
3407
- ctx.options().rust_features().associated_const
3408
- {
3891
+ if enum_ty.name().is_some() {
3409
3892
  let enum_canonical_name = &ident;
3410
3893
  let variant_name =
3411
3894
  ctx.rust_ident_raw(&*mangled_name);
@@ -3422,7 +3905,7 @@ impl CodeGenerator for Enum {
3422
3905
  &ident,
3423
3906
  &Ident::new(&mangled_name, Span::call_site()),
3424
3907
  existing_variant_name,
3425
- enum_rust_ty.clone(),
3908
+ &enum_rust_ty,
3426
3909
  result,
3427
3910
  );
3428
3911
  }
@@ -3430,9 +3913,9 @@ impl CodeGenerator for Enum {
3430
3913
  builder = builder.with_variant(
3431
3914
  ctx,
3432
3915
  variant,
3916
+ variant_doc,
3433
3917
  constant_mangling_prefix,
3434
- enum_rust_ty.clone(),
3435
- result,
3918
+ &enum_rust_ty,
3436
3919
  enum_ty.name().is_some(),
3437
3920
  );
3438
3921
  }
@@ -3441,9 +3924,9 @@ impl CodeGenerator for Enum {
3441
3924
  builder = builder.with_variant(
3442
3925
  ctx,
3443
3926
  variant,
3927
+ variant_doc,
3444
3928
  constant_mangling_prefix,
3445
- enum_rust_ty.clone(),
3446
- result,
3929
+ &enum_rust_ty,
3447
3930
  enum_ty.name().is_some(),
3448
3931
  );
3449
3932
 
@@ -3462,7 +3945,7 @@ impl CodeGenerator for Enum {
3462
3945
  parent_canonical_name.as_ref().unwrap();
3463
3946
 
3464
3947
  Ident::new(
3465
- &format!("{}_{}", parent_name, variant_name),
3948
+ &format!("{parent_name}_{variant_name}"),
3466
3949
  Span::call_site(),
3467
3950
  )
3468
3951
  };
@@ -3473,7 +3956,7 @@ impl CodeGenerator for Enum {
3473
3956
  &ident,
3474
3957
  &mangled_name,
3475
3958
  &variant_name,
3476
- enum_rust_ty.clone(),
3959
+ &enum_rust_ty,
3477
3960
  result,
3478
3961
  );
3479
3962
  }
@@ -3483,17 +3966,24 @@ impl CodeGenerator for Enum {
3483
3966
  }
3484
3967
  }
3485
3968
 
3486
- let item = builder.build(ctx, enum_rust_ty, result);
3969
+ let item = builder.build(ctx, &enum_rust_ty);
3487
3970
  result.push(item);
3488
3971
  }
3489
3972
  }
3490
3973
 
3974
+ struct EnumVariantInfo {
3975
+ variant_name: Ident,
3976
+ variant_doc: proc_macro2::TokenStream,
3977
+ value: proc_macro2::TokenStream,
3978
+ }
3979
+
3491
3980
  /// Enum for the default type of macro constants.
3492
- #[derive(Copy, Clone, PartialEq, Eq, Debug)]
3981
+ #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
3493
3982
  pub enum MacroTypeVariation {
3494
3983
  /// Use i32 or i64
3495
3984
  Signed,
3496
3985
  /// Use u32 or u64
3986
+ #[default]
3497
3987
  Unsigned,
3498
3988
  }
3499
3989
 
@@ -3507,13 +3997,7 @@ impl fmt::Display for MacroTypeVariation {
3507
3997
  }
3508
3998
  }
3509
3999
 
3510
- impl Default for MacroTypeVariation {
3511
- fn default() -> MacroTypeVariation {
3512
- MacroTypeVariation::Unsigned
3513
- }
3514
- }
3515
-
3516
- impl std::str::FromStr for MacroTypeVariation {
4000
+ impl FromStr for MacroTypeVariation {
3517
4001
  type Err = std::io::Error;
3518
4002
 
3519
4003
  /// Create a `MacroTypeVariation` from a string.
@@ -3533,13 +4017,14 @@ impl std::str::FromStr for MacroTypeVariation {
3533
4017
  }
3534
4018
 
3535
4019
  /// Enum for how aliases should be translated.
3536
- #[derive(Copy, Clone, PartialEq, Eq, Debug)]
4020
+ #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
3537
4021
  pub enum AliasVariation {
3538
4022
  /// Convert to regular Rust alias
4023
+ #[default]
3539
4024
  TypeAlias,
3540
4025
  /// Create a new type by wrapping the old type in a struct and using #[repr(transparent)]
3541
4026
  NewType,
3542
- /// Same as NewStruct but also impl Deref to be able to use the methods of the wrapped type
4027
+ /// Same as `NewType` but also impl Deref to be able to use the methods of the wrapped type
3543
4028
  NewTypeDeref,
3544
4029
  }
3545
4030
 
@@ -3555,13 +4040,7 @@ impl fmt::Display for AliasVariation {
3555
4040
  }
3556
4041
  }
3557
4042
 
3558
- impl Default for AliasVariation {
3559
- fn default() -> AliasVariation {
3560
- AliasVariation::TypeAlias
3561
- }
3562
- }
3563
-
3564
- impl std::str::FromStr for AliasVariation {
4043
+ impl FromStr for AliasVariation {
3565
4044
  type Err = std::io::Error;
3566
4045
 
3567
4046
  /// Create an `AliasVariation` from a string.
@@ -3610,7 +4089,7 @@ impl Default for NonCopyUnionStyle {
3610
4089
  }
3611
4090
  }
3612
4091
 
3613
- impl std::str::FromStr for NonCopyUnionStyle {
4092
+ impl FromStr for NonCopyUnionStyle {
3614
4093
  type Err = std::io::Error;
3615
4094
 
3616
4095
  fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -3650,7 +4129,7 @@ pub(crate) trait TryToOpaque {
3650
4129
  extra: &Self::Extra,
3651
4130
  ) -> error::Result<syn::Type> {
3652
4131
  self.try_get_layout(ctx, extra)
3653
- .map(|layout| helpers::blob(ctx, layout))
4132
+ .map(|layout| helpers::blob(ctx, layout, true))
3654
4133
  }
3655
4134
  }
3656
4135
 
@@ -3676,7 +4155,7 @@ pub(crate) trait ToOpaque: TryToOpaque {
3676
4155
  extra: &Self::Extra,
3677
4156
  ) -> syn::Type {
3678
4157
  let layout = self.get_layout(ctx, extra);
3679
- helpers::blob(ctx, layout)
4158
+ helpers::blob(ctx, layout, true)
3680
4159
  }
3681
4160
  }
3682
4161
 
@@ -3727,9 +4206,9 @@ where
3727
4206
  ) -> error::Result<syn::Type> {
3728
4207
  self.try_to_rust_ty(ctx, extra).or_else(|_| {
3729
4208
  if let Ok(layout) = self.try_get_layout(ctx, extra) {
3730
- Ok(helpers::blob(ctx, layout))
4209
+ Ok(helpers::blob(ctx, layout, true))
3731
4210
  } else {
3732
- Err(error::Error::NoLayoutForOpaqueBlob)
4211
+ Err(Error::NoLayoutForOpaqueBlob)
3733
4212
  }
3734
4213
  })
3735
4214
  }
@@ -3744,11 +4223,11 @@ where
3744
4223
  /// ### Fallible vs. Infallible Conversions to Rust Types
3745
4224
  ///
3746
4225
  /// When should one use this infallible `ToRustTyOrOpaque` trait versus the
3747
- /// fallible `TryTo{RustTy, Opaque, RustTyOrOpaque}` triats? All fallible trait
4226
+ /// fallible `TryTo{RustTy, Opaque, RustTyOrOpaque}` traits? All fallible trait
3748
4227
  /// implementations that need to convert another thing into a Rust type or
3749
4228
  /// opaque blob in a nested manner should also use fallible trait methods and
3750
4229
  /// propagate failure up the stack. Only infallible functions and methods like
3751
- /// CodeGenerator implementations should use the infallible
4230
+ /// `CodeGenerator` implementations should use the infallible
3752
4231
  /// `ToRustTyOrOpaque`. The further out we push error recovery, the more likely
3753
4232
  /// we are to get a usable `Layout` even if we can't generate an equivalent Rust
3754
4233
  /// type for a C++ construct.
@@ -3840,7 +4319,7 @@ impl TryToOpaque for Type {
3840
4319
  ctx: &BindgenContext,
3841
4320
  _: &Item,
3842
4321
  ) -> error::Result<Layout> {
3843
- self.layout(ctx).ok_or(error::Error::NoLayoutForOpaqueBlob)
4322
+ self.layout(ctx).ok_or(Error::NoLayoutForOpaqueBlob)
3844
4323
  }
3845
4324
  }
3846
4325
 
@@ -3982,7 +4461,7 @@ impl TryToRustTy for Type {
3982
4461
  Ok(syn::parse_quote! { #name })
3983
4462
  }
3984
4463
  ref u @ TypeKind::UnresolvedTypeRef(..) => {
3985
- unreachable!("Should have been resolved after parsing {:?}!", u)
4464
+ unreachable!("Should have been resolved after parsing {u:?}!")
3986
4465
  }
3987
4466
  }
3988
4467
  }
@@ -3998,7 +4477,7 @@ impl TryToOpaque for TemplateInstantiation {
3998
4477
  ) -> error::Result<Layout> {
3999
4478
  item.expect_type()
4000
4479
  .layout(ctx)
4001
- .ok_or(error::Error::NoLayoutForOpaqueBlob)
4480
+ .ok_or(Error::NoLayoutForOpaqueBlob)
4002
4481
  }
4003
4482
  }
4004
4483
 
@@ -4011,7 +4490,7 @@ impl TryToRustTy for TemplateInstantiation {
4011
4490
  item: &Item,
4012
4491
  ) -> error::Result<syn::Type> {
4013
4492
  if self.is_opaque(ctx, item) {
4014
- return Err(error::Error::InstantiationOfOpaqueType);
4493
+ return Err(Error::InstantiationOfOpaqueType);
4015
4494
  }
4016
4495
 
4017
4496
  let def = self
@@ -4033,7 +4512,7 @@ impl TryToRustTy for TemplateInstantiation {
4033
4512
  // template specialization, and we've hit an instantiation of
4034
4513
  // that partial specialization.
4035
4514
  extra_assert!(def.is_opaque(ctx, &()));
4036
- return Err(error::Error::InstantiationOfOpaqueType);
4515
+ return Err(Error::InstantiationOfOpaqueType);
4037
4516
  }
4038
4517
 
4039
4518
  // TODO: If the definition type is a template class/struct
@@ -4085,7 +4564,7 @@ impl TryToRustTy for FunctionSig {
4085
4564
  syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret },
4086
4565
  ),
4087
4566
  Err(err) => {
4088
- if matches!(err, error::Error::UnsupportedAbi(_)) {
4567
+ if matches!(err, Error::UnsupportedAbi(_)) {
4089
4568
  unsupported_abi_diagnostic(
4090
4569
  self.name(),
4091
4570
  self.is_variadic(),
@@ -4114,16 +4593,16 @@ impl CodeGenerator for Function {
4114
4593
  result: &mut CodegenResult<'_>,
4115
4594
  item: &Item,
4116
4595
  ) -> Self::Return {
4117
- debug!("<Function as CodeGenerator>::codegen: item = {:?}", item);
4596
+ debug!("<Function as CodeGenerator>::codegen: item = {item:?}");
4118
4597
  debug_assert!(item.is_enabled_for_codegen(ctx));
4598
+ let id = DiscoveredItemId::new(item.id().as_usize());
4119
4599
 
4120
4600
  let is_internal = matches!(self.linkage(), Linkage::Internal);
4121
4601
 
4122
4602
  let signature_item = ctx.resolve_item(self.signature());
4123
4603
  let signature = signature_item.kind().expect_type().canonical_type(ctx);
4124
- let signature = match *signature.kind() {
4125
- TypeKind::Function(ref sig) => sig,
4126
- _ => panic!("Signature kind is not a Function: {:?}", signature),
4604
+ let TypeKind::Function(ref signature) = *signature.kind() else {
4605
+ panic!("Signature kind is not a Function: {signature:?}")
4127
4606
  };
4128
4607
 
4129
4608
  if is_internal {
@@ -4141,18 +4620,24 @@ impl CodeGenerator for Function {
4141
4620
  }
4142
4621
  }
4143
4622
 
4144
- // Pure virtual methods have no actual symbol, so we can't generate
4145
- // something meaningful for them.
4146
- let is_dynamic_function = match self.kind() {
4147
- FunctionKind::Method(ref method_kind)
4148
- if method_kind.is_pure_virtual() =>
4149
- {
4150
- return None;
4623
+ let is_pure_virtual = match self.kind() {
4624
+ FunctionKind::Method(ref method_kind) => {
4625
+ method_kind.is_pure_virtual()
4151
4626
  }
4627
+ FunctionKind::Function => false,
4628
+ };
4629
+ if is_pure_virtual && !ctx.options().generate_pure_virtual_functions {
4630
+ // Pure virtual methods have no actual symbol, so we can't generate
4631
+ // something meaningful for them. Downstream code postprocessors
4632
+ // might want to find out about them.
4633
+ return None;
4634
+ }
4635
+
4636
+ let is_dynamic_function = match self.kind() {
4152
4637
  FunctionKind::Function => {
4153
4638
  ctx.options().dynamic_library_name.is_some()
4154
4639
  }
4155
- _ => false,
4640
+ FunctionKind::Method(_) => false,
4156
4641
  };
4157
4642
 
4158
4643
  // Similar to static member variables in a class template, we can't
@@ -4180,7 +4665,7 @@ impl CodeGenerator for Function {
4180
4665
 
4181
4666
  let mut attributes = vec![];
4182
4667
 
4183
- if ctx.options().rust_features().must_use_function {
4668
+ if true {
4184
4669
  let must_use = signature.must_use() || {
4185
4670
  let ret_ty = signature
4186
4671
  .return_type()
@@ -4196,12 +4681,12 @@ impl CodeGenerator for Function {
4196
4681
  }
4197
4682
 
4198
4683
  if let Some(comment) = item.comment(ctx) {
4199
- attributes.push(attributes::doc(comment));
4684
+ attributes.push(attributes::doc(&comment));
4200
4685
  }
4201
4686
 
4202
4687
  let abi = match signature.abi(ctx, Some(name)) {
4203
4688
  Err(err) => {
4204
- if matches!(err, error::Error::UnsupportedAbi(_)) {
4689
+ if matches!(err, Error::UnsupportedAbi(_)) {
4205
4690
  unsupported_abi_diagnostic(
4206
4691
  name,
4207
4692
  signature.is_variadic(),
@@ -4215,8 +4700,7 @@ impl CodeGenerator for Function {
4215
4700
  }
4216
4701
  Ok(ClangAbi::Unknown(unknown_abi)) => {
4217
4702
  panic!(
4218
- "Invalid or unknown abi {:?} for function {:?} ({:?})",
4219
- unknown_abi, canonical_name, self
4703
+ "Invalid or unknown abi {unknown_abi:?} for function {canonical_name:?} ({self:?})"
4220
4704
  );
4221
4705
  }
4222
4706
  Ok(abi) => abi,
@@ -4226,24 +4710,30 @@ impl CodeGenerator for Function {
4226
4710
  // suffix.
4227
4711
  let times_seen = result.overload_number(&canonical_name);
4228
4712
  if times_seen > 0 {
4229
- write!(&mut canonical_name, "{}", times_seen).unwrap();
4713
+ write!(&mut canonical_name, "{times_seen}").unwrap();
4230
4714
  }
4715
+ ctx.options().for_each_callback(|cb| {
4716
+ cb.new_item_found(
4717
+ id,
4718
+ DiscoveredItem::Function {
4719
+ final_name: canonical_name.to_string(),
4720
+ },
4721
+ );
4722
+ });
4231
4723
 
4232
- let mut has_link_name_attr = false;
4233
- if let Some(link_name) = self.link_name() {
4234
- attributes.push(attributes::link_name::<false>(link_name));
4235
- has_link_name_attr = true;
4236
- } else {
4237
- let link_name = mangled_name.unwrap_or(name);
4238
- if !is_dynamic_function &&
4239
- !utils::names_will_be_identical_after_mangling(
4240
- &canonical_name,
4241
- link_name,
4242
- Some(abi),
4243
- )
4244
- {
4724
+ let link_name_attr = self.link_name().or_else(|| {
4725
+ let mangled_name = mangled_name.unwrap_or(name);
4726
+ (!utils::names_will_be_identical_after_mangling(
4727
+ &canonical_name,
4728
+ mangled_name,
4729
+ Some(abi),
4730
+ ))
4731
+ .then_some(mangled_name)
4732
+ });
4733
+
4734
+ if let Some(link_name) = link_name_attr {
4735
+ if !is_dynamic_function {
4245
4736
  attributes.push(attributes::link_name::<false>(link_name));
4246
- has_link_name_attr = true;
4247
4737
  }
4248
4738
  }
4249
4739
 
@@ -4255,8 +4745,9 @@ impl CodeGenerator for Function {
4255
4745
  quote! { #[link(wasm_import_module = #name)] }
4256
4746
  });
4257
4747
 
4258
- let should_wrap =
4259
- is_internal && ctx.options().wrap_static_fns && !has_link_name_attr;
4748
+ let should_wrap = is_internal &&
4749
+ ctx.options().wrap_static_fns &&
4750
+ link_name_attr.is_none();
4260
4751
 
4261
4752
  if should_wrap {
4262
4753
  let name = canonical_name.clone() + ctx.wrap_static_fns_suffix();
@@ -4298,9 +4789,16 @@ impl CodeGenerator for Function {
4298
4789
  let ret = utils::fnsig_return_ty(ctx, signature);
4299
4790
 
4300
4791
  let ident = ctx.rust_ident(ident);
4792
+
4793
+ let safety = ctx
4794
+ .options()
4795
+ .rust_features
4796
+ .unsafe_extern_blocks
4797
+ .then(|| quote!(unsafe));
4798
+
4301
4799
  let tokens = quote! {
4302
4800
  #wasm_link_attribute
4303
- extern #abi {
4801
+ #safety extern #abi {
4304
4802
  #(#attributes)*
4305
4803
  pub fn #ident ( #( #args ),* ) #ret;
4306
4804
  }
@@ -4315,19 +4813,22 @@ impl CodeGenerator for Function {
4315
4813
 
4316
4814
  // If we're doing dynamic binding generation, add to the dynamic items.
4317
4815
  if is_dynamic_function {
4816
+ let ident_str = ident.to_string();
4817
+ let symbol = link_name_attr.unwrap_or(&ident_str);
4318
4818
  let args_identifiers =
4319
4819
  utils::fnsig_argument_identifiers(ctx, signature);
4320
4820
  let ret_ty = utils::fnsig_return_ty(ctx, signature);
4321
- result.dynamic_items().push(
4322
- ident,
4821
+ result.dynamic_items().push_func(
4822
+ &ident,
4823
+ symbol,
4323
4824
  abi,
4324
4825
  signature.is_variadic(),
4325
4826
  ctx.options().dynamic_link_require_all,
4326
- args,
4327
- args_identifiers,
4328
- ret,
4329
- ret_ty,
4330
- attributes,
4827
+ &args,
4828
+ &args_identifiers,
4829
+ &ret,
4830
+ &ret_ty,
4831
+ &attributes,
4331
4832
  ctx,
4332
4833
  );
4333
4834
  } else {
@@ -4343,13 +4844,11 @@ fn unsupported_abi_diagnostic(
4343
4844
  variadic: bool,
4344
4845
  location: Option<&crate::clang::SourceLocation>,
4345
4846
  ctx: &BindgenContext,
4346
- error: &error::Error,
4847
+ error: &Error,
4347
4848
  ) {
4348
4849
  warn!(
4349
- "Skipping {}function `{}` because the {}",
4850
+ "Skipping {}function `{fn_name}` because the {error}",
4350
4851
  if variadic { "variadic " } else { "" },
4351
- fn_name,
4352
- error
4353
4852
  );
4354
4853
 
4355
4854
  #[cfg(feature = "experimental")]
@@ -4359,16 +4858,14 @@ fn unsupported_abi_diagnostic(
4359
4858
  let mut diag = Diagnostic::default();
4360
4859
  diag.with_title(
4361
4860
  format!(
4362
- "Skipping {}function `{}` because the {}",
4861
+ "Skipping {}function `{fn_name}` because the {error}",
4363
4862
  if variadic { "variadic " } else { "" },
4364
- fn_name,
4365
- error
4366
4863
  ),
4367
- Level::Warn,
4864
+ Level::Warning,
4368
4865
  )
4369
4866
  .add_annotation(
4370
4867
  "No code will be generated for this function.",
4371
- Level::Warn,
4868
+ Level::Warning,
4372
4869
  )
4373
4870
  .add_annotation(
4374
4871
  format!(
@@ -4392,7 +4889,7 @@ fn unsupported_abi_diagnostic(
4392
4889
  }
4393
4890
  }
4394
4891
 
4395
- diag.display()
4892
+ diag.display();
4396
4893
  }
4397
4894
  }
4398
4895
 
@@ -4402,8 +4899,7 @@ fn variadic_fn_diagnostic(
4402
4899
  _ctx: &BindgenContext,
4403
4900
  ) {
4404
4901
  warn!(
4405
- "Cannot generate wrapper for the static variadic function `{}`.",
4406
- fn_name,
4902
+ "Cannot generate wrapper for the static variadic function `{fn_name}`."
4407
4903
  );
4408
4904
 
4409
4905
  #[cfg(feature = "experimental")]
@@ -4412,7 +4908,7 @@ fn variadic_fn_diagnostic(
4412
4908
 
4413
4909
  let mut diag = Diagnostic::default();
4414
4910
 
4415
- diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warn)
4911
+ diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::Warning)
4416
4912
  .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note)
4417
4913
  .add_annotation("No code will be generated for this function.", Level::Note);
4418
4914
 
@@ -4430,7 +4926,7 @@ fn variadic_fn_diagnostic(
4430
4926
  }
4431
4927
  }
4432
4928
 
4433
- diag.display()
4929
+ diag.display();
4434
4930
  }
4435
4931
  }
4436
4932
 
@@ -4445,7 +4941,7 @@ fn objc_method_codegen(
4445
4941
  // This would ideally resolve the method into an Item, and use
4446
4942
  // Item::process_before_codegen; however, ObjC methods are not currently
4447
4943
  // made into function items.
4448
- let name = format!("{}::{}{}", rust_class_name, prefix, method.rust_name());
4944
+ let name = format!("{rust_class_name}::{prefix}{}", method.rust_name());
4449
4945
  if ctx.options().blocklisted_items.matches(name) {
4450
4946
  return;
4451
4947
  }
@@ -4482,8 +4978,7 @@ fn objc_method_codegen(
4482
4978
  ctx.wrap_unsafe_ops(body)
4483
4979
  };
4484
4980
 
4485
- let method_name =
4486
- ctx.rust_ident(format!("{}{}", prefix, method.rust_name()));
4981
+ let method_name = ctx.rust_ident(format!("{prefix}{}", method.rust_name()));
4487
4982
 
4488
4983
  methods.push(quote! {
4489
4984
  unsafe fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized {
@@ -4584,7 +5079,7 @@ impl CodeGenerator for ObjCInterface {
4584
5079
  };
4585
5080
  result.push(struct_block);
4586
5081
  let mut protocol_set: HashSet<ItemId> = Default::default();
4587
- for protocol_id in self.conforms_to.iter() {
5082
+ for protocol_id in &self.conforms_to {
4588
5083
  protocol_set.insert(*protocol_id);
4589
5084
  let protocol_name = ctx.rust_ident(
4590
5085
  ctx.resolve_type(protocol_id.expect_type_id(ctx))
@@ -4606,9 +5101,8 @@ impl CodeGenerator for ObjCInterface {
4606
5101
  .expect_type()
4607
5102
  .kind();
4608
5103
 
4609
- let parent = match parent {
4610
- TypeKind::ObjCInterface(ref parent) => parent,
4611
- _ => break,
5104
+ let TypeKind::ObjCInterface(parent) = parent else {
5105
+ break;
4612
5106
  };
4613
5107
  parent_class = parent.parent_class;
4614
5108
 
@@ -4629,7 +5123,7 @@ impl CodeGenerator for ObjCInterface {
4629
5123
  }
4630
5124
  };
4631
5125
  result.push(impl_trait);
4632
- for protocol_id in parent.conforms_to.iter() {
5126
+ for protocol_id in &parent.conforms_to {
4633
5127
  if protocol_set.insert(*protocol_id) {
4634
5128
  let protocol_name = ctx.rust_ident(
4635
5129
  ctx.resolve_type(protocol_id.expect_type_id(ctx))
@@ -4656,8 +5150,7 @@ impl CodeGenerator for ObjCInterface {
4656
5150
  result.push(from_block);
4657
5151
 
4658
5152
  let error_msg = format!(
4659
- "This {} cannot be downcasted to {}",
4660
- parent_struct_name, child_struct_name
5153
+ "This {parent_struct_name} cannot be downcasted to {child_struct_name}"
4661
5154
  );
4662
5155
  let try_into_block = quote! {
4663
5156
  impl std::convert::TryFrom<#parent_struct> for #class_name {
@@ -4716,7 +5209,7 @@ pub(crate) fn codegen(
4716
5209
  let codegen_items = context.codegen_items();
4717
5210
  for (id, item) in context.items() {
4718
5211
  if codegen_items.contains(&id) {
4719
- println!("ir: {:?} = {:#?}", id, item);
5212
+ println!("ir: {id:?} = {item:#?}");
4720
5213
  }
4721
5214
  }
4722
5215
  }
@@ -4724,10 +5217,9 @@ pub(crate) fn codegen(
4724
5217
  if let Some(path) = context.options().emit_ir_graphviz.as_ref() {
4725
5218
  match dot::write_dot_file(context, path) {
4726
5219
  Ok(()) => info!(
4727
- "Your dot file was generated successfully into: {}",
4728
- path
5220
+ "Your dot file was generated successfully into: {path}"
4729
5221
  ),
4730
- Err(e) => warn!("{}", e),
5222
+ Err(e) => warn!("{e}"),
4731
5223
  }
4732
5224
  }
4733
5225
 
@@ -4737,7 +5229,7 @@ pub(crate) fn codegen(
4737
5229
  "Your depfile was generated successfully into: {}",
4738
5230
  spec.depfile_path.display()
4739
5231
  ),
4740
- Err(e) => warn!("{}", e),
5232
+ Err(e) => warn!("{e}"),
4741
5233
  }
4742
5234
  }
4743
5235
 
@@ -4750,7 +5242,7 @@ pub(crate) fn codegen(
4750
5242
  if let Some(ref lib_name) = context.options().dynamic_library_name {
4751
5243
  let lib_ident = context.rust_ident(lib_name);
4752
5244
  let dynamic_items_tokens =
4753
- result.dynamic_items().get_tokens(lib_ident, context);
5245
+ result.dynamic_items().get_tokens(&lib_ident, context);
4754
5246
  result.push(dynamic_items_tokens);
4755
5247
  }
4756
5248
 
@@ -4764,6 +5256,7 @@ pub(crate) fn codegen(
4764
5256
  }
4765
5257
 
4766
5258
  pub(crate) mod utils {
5259
+ use super::helpers::BITFIELD_UNIT;
4767
5260
  use super::serialize::CSerialize;
4768
5261
  use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque};
4769
5262
  use crate::ir::context::BindgenContext;
@@ -4786,14 +5279,10 @@ pub(crate) mod utils {
4786
5279
  return Ok(());
4787
5280
  }
4788
5281
 
4789
- let path = context
4790
- .options()
4791
- .wrap_static_fns_path
4792
- .as_ref()
4793
- .map(PathBuf::from)
4794
- .unwrap_or_else(|| {
4795
- std::env::temp_dir().join("bindgen").join("extern")
4796
- });
5282
+ let path = context.options().wrap_static_fns_path.as_ref().map_or_else(
5283
+ || std::env::temp_dir().join("bindgen").join("extern"),
5284
+ PathBuf::from,
5285
+ );
4797
5286
 
4798
5287
  let dir = path.parent().unwrap();
4799
5288
 
@@ -4814,7 +5303,7 @@ pub(crate) mod utils {
4814
5303
 
4815
5304
  if !context.options().input_headers.is_empty() {
4816
5305
  for header in &context.options().input_headers {
4817
- writeln!(code, "#include \"{}\"", header)?;
5306
+ writeln!(code, "#include \"{header}\"")?;
4818
5307
  }
4819
5308
 
4820
5309
  writeln!(code)?;
@@ -4822,7 +5311,7 @@ pub(crate) mod utils {
4822
5311
 
4823
5312
  if !context.options().input_header_contents.is_empty() {
4824
5313
  for (name, contents) in &context.options().input_header_contents {
4825
- writeln!(code, "// {}\n{}", name, contents)?;
5314
+ writeln!(code, "// {name}\n{contents}")?;
4826
5315
  }
4827
5316
 
4828
5317
  writeln!(code)?;
@@ -4862,10 +5351,10 @@ pub(crate) mod utils {
4862
5351
  }
4863
5352
  match ty.kind() {
4864
5353
  TypeKind::Alias(type_id_alias) => {
4865
- type_id = *type_id_alias
5354
+ type_id = *type_id_alias;
4866
5355
  }
4867
5356
  TypeKind::ResolvedTypeRef(type_id_typedef) => {
4868
- type_id = *type_id_typedef
5357
+ type_id = *type_id_typedef;
4869
5358
  }
4870
5359
  _ => break,
4871
5360
  }
@@ -4900,8 +5389,19 @@ pub(crate) mod utils {
4900
5389
  ctx: &BindgenContext,
4901
5390
  result: &mut Vec<proc_macro2::TokenStream>,
4902
5391
  ) {
4903
- let bitfield_unit_src = include_str!("./bitfield_unit.rs");
4904
- let bitfield_unit_src = if ctx.options().rust_features().min_const_fn {
5392
+ if ctx.options().blocklisted_items.matches(BITFIELD_UNIT) ||
5393
+ ctx.options().blocklisted_types.matches(BITFIELD_UNIT)
5394
+ {
5395
+ return;
5396
+ }
5397
+
5398
+ let bitfield_unit_src = if ctx.options().rust_features().raw_ref_macros
5399
+ {
5400
+ include_str!("./bitfield_unit_raw_ref_macros.rs")
5401
+ } else {
5402
+ include_str!("./bitfield_unit.rs")
5403
+ };
5404
+ let bitfield_unit_src = if true {
4905
5405
  Cow::Borrowed(bitfield_unit_src)
4906
5406
  } else {
4907
5407
  Cow::Owned(bitfield_unit_src.replace("const fn ", "fn "))
@@ -4967,7 +5467,7 @@ pub(crate) mod utils {
4967
5467
 
4968
5468
  // If the target supports `const fn`, declare eligible functions
4969
5469
  // as `const fn` else just `fn`.
4970
- let const_fn = if ctx.options().rust_features().min_const_fn {
5470
+ let const_fn = if true {
4971
5471
  quote! { const fn }
4972
5472
  } else {
4973
5473
  quote! { fn }
@@ -5079,7 +5579,7 @@ pub(crate) mod utils {
5079
5579
 
5080
5580
  // If the target supports `const fn`, declare eligible functions
5081
5581
  // as `const fn` else just `fn`.
5082
- let const_fn = if ctx.options().rust_features().min_const_fn {
5582
+ let const_fn = if true {
5083
5583
  quote! { const fn }
5084
5584
  } else {
5085
5585
  quote! { fn }
@@ -5178,6 +5678,25 @@ pub(crate) mod utils {
5178
5678
  result.extend(old_items);
5179
5679
  }
5180
5680
 
5681
+ pub(crate) fn prepend_opaque_array_type(
5682
+ result: &mut Vec<proc_macro2::TokenStream>,
5683
+ ) {
5684
+ let ty = quote! {
5685
+ /// If Bindgen could only determine the size and alignment of a
5686
+ /// type, it is represented like this.
5687
+ #[derive(PartialEq, Copy, Clone, Debug, Hash)]
5688
+ #[repr(C)]
5689
+ pub struct __BindgenOpaqueArray<T: Copy, const N: usize>(pub [T; N]);
5690
+ impl<T: Copy + Default, const N: usize> Default for __BindgenOpaqueArray<T, N> {
5691
+ fn default() -> Self {
5692
+ Self([<T as Default>::default(); N])
5693
+ }
5694
+ }
5695
+ };
5696
+
5697
+ result.insert(0, ty);
5698
+ }
5699
+
5181
5700
  pub(crate) fn build_path(
5182
5701
  item: &Item,
5183
5702
  ctx: &BindgenContext,
@@ -5263,7 +5782,7 @@ pub(crate) mod utils {
5263
5782
 
5264
5783
  pub(crate) fn fnsig_argument_type(
5265
5784
  ctx: &BindgenContext,
5266
- ty: &TypeId,
5785
+ ty: TypeId,
5267
5786
  ) -> syn::Type {
5268
5787
  use super::ToPtr;
5269
5788
 
@@ -5285,7 +5804,8 @@ pub(crate) mod utils {
5285
5804
  } else {
5286
5805
  t.to_rust_ty_or_opaque(ctx, &())
5287
5806
  };
5288
- stream.to_ptr(ctx.resolve_type(t).is_const())
5807
+ stream
5808
+ .to_ptr(ctx.resolve_type(t).is_const() || arg_ty.is_const())
5289
5809
  }
5290
5810
  TypeKind::Pointer(inner) => {
5291
5811
  let inner = ctx.resolve_item(inner);
@@ -5305,7 +5825,7 @@ pub(crate) mod utils {
5305
5825
 
5306
5826
  pub(crate) fn fnsig_arguments_iter<
5307
5827
  'a,
5308
- I: Iterator<Item = &'a (Option<String>, crate::ir::context::TypeId)>,
5828
+ I: Iterator<Item = &'a (Option<String>, TypeId)>,
5309
5829
  >(
5310
5830
  ctx: &BindgenContext,
5311
5831
  args_iter: I,
@@ -5314,14 +5834,13 @@ pub(crate) mod utils {
5314
5834
  let mut unnamed_arguments = 0;
5315
5835
  let mut args = args_iter
5316
5836
  .map(|(name, ty)| {
5317
- let arg_ty = fnsig_argument_type(ctx, ty);
5837
+ let arg_ty = fnsig_argument_type(ctx, *ty);
5318
5838
 
5319
- let arg_name = match *name {
5320
- Some(ref name) => ctx.rust_mangle(name).into_owned(),
5321
- None => {
5322
- unnamed_arguments += 1;
5323
- format!("arg{}", unnamed_arguments)
5324
- }
5839
+ let arg_name = if let Some(ref name) = *name {
5840
+ ctx.rust_mangle(name).into_owned()
5841
+ } else {
5842
+ unnamed_arguments += 1;
5843
+ format!("arg{unnamed_arguments}")
5325
5844
  };
5326
5845
 
5327
5846
  assert!(!arg_name.is_empty());
@@ -5334,7 +5853,7 @@ pub(crate) mod utils {
5334
5853
  .collect::<Vec<_>>();
5335
5854
 
5336
5855
  if is_variadic {
5337
- args.push(quote! { ... })
5856
+ args.push(quote! { ... });
5338
5857
  }
5339
5858
 
5340
5859
  args
@@ -5360,12 +5879,11 @@ pub(crate) mod utils {
5360
5879
  .argument_types()
5361
5880
  .iter()
5362
5881
  .map(|&(ref name, _ty)| {
5363
- let arg_name = match *name {
5364
- Some(ref name) => ctx.rust_mangle(name).into_owned(),
5365
- None => {
5366
- unnamed_arguments += 1;
5367
- format!("arg{}", unnamed_arguments)
5368
- }
5882
+ let arg_name = if let Some(ref name) = *name {
5883
+ ctx.rust_mangle(name).into_owned()
5884
+ } else {
5885
+ unnamed_arguments += 1;
5886
+ format!("arg{unnamed_arguments}")
5369
5887
  };
5370
5888
 
5371
5889
  assert!(!arg_name.is_empty());
@@ -5442,7 +5960,7 @@ pub(crate) mod utils {
5442
5960
 
5443
5961
  // Check that the mangled name contains the canonical name after the
5444
5962
  // prefix
5445
- if &mangled_name[1..canonical_name.len() + 1] != canonical_name {
5963
+ if &mangled_name[1..=canonical_name.len()] != canonical_name {
5446
5964
  return false;
5447
5965
  }
5448
5966