summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-11-30 12:00:19 +0100
committerGitHub <noreply@github.com>2018-11-30 12:00:19 +0100
commit29a63476f8b22994c57e547790b69026eb952a16 (patch)
treeb25dacf9b5be1fedcf961a770170831c0e8f74cf
parent33912cfcdc34bda21599de29cd7b4241eb7c341a (diff)
parent7b1406dc90f67fafca61dba915ac57b9d2d7d2d4 (diff)
Merge pull request #1409 from emilio/update-some-crates. r=emilio
Update which, quote and proc_macro.
-rw-r--r--Cargo.lock61
-rw-r--r--Cargo.toml8
-rw-r--r--bindgen-integration/Cargo.toml2
-rw-r--r--bindgen-integration/build.rs4
-rw-r--r--src/codegen/helpers.rs67
-rw-r--r--src/codegen/impl_debug.rs16
-rw-r--r--src/codegen/impl_partialeq.rs9
-rw-r--r--src/codegen/mod.rs202
-rw-r--r--src/codegen/struct_layout.rs11
-rw-r--r--src/ir/context.rs10
-rw-r--r--src/ir/function.rs4
-rw-r--r--src/ir/objc.rs9
-rw-r--r--src/lib.rs4
-rw-r--r--tests/expectations/tests/accessors.rs9
-rw-r--r--tests/expectations/tests/annotation_hide.rs10
-rw-r--r--tests/expectations/tests/array-of-zero-sized-types.rs10
-rw-r--r--tests/expectations/tests/bitfield-32bit-overflow.rs23
-rw-r--r--tests/expectations/tests/bitfield-large.rs23
-rw-r--r--tests/expectations/tests/bitfield-method-same-name.rs23
-rw-r--r--tests/expectations/tests/bitfield_align.rs23
-rw-r--r--tests/expectations/tests/bitfield_align_2.rs23
-rw-r--r--tests/expectations/tests/bitfield_method_mangling.rs23
-rw-r--r--tests/expectations/tests/blacklist-and-impl-debug.rs9
-rw-r--r--tests/expectations/tests/class_use_as.rs10
-rw-r--r--tests/expectations/tests/comment-indent.rs8
-rw-r--r--tests/expectations/tests/contains-vs-inherits-zero-sized.rs10
-rw-r--r--tests/expectations/tests/derive-bitfield-method-same-name.rs24
-rw-r--r--tests/expectations/tests/derive-clone.rs10
-rw-r--r--tests/expectations/tests/derive-clone_1_0.rs10
-rw-r--r--tests/expectations/tests/derive-debug-bitfield-core.rs16
-rw-r--r--tests/expectations/tests/derive-debug-bitfield.rs23
-rw-r--r--tests/expectations/tests/derive-default-and-blacklist.rs9
-rw-r--r--tests/expectations/tests/derive-hash-and-blacklist.rs9
-rw-r--r--tests/expectations/tests/derive-hash-blacklisting.rs9
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs10
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-float-array.rs10
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-pointer.rs7
-rw-r--r--tests/expectations/tests/derive-hash-template-def-float.rs10
-rw-r--r--tests/expectations/tests/derive-hash-template-inst-float.rs10
-rw-r--r--tests/expectations/tests/derive-partialeq-and-blacklist.rs9
-rw-r--r--tests/expectations/tests/derive-partialeq-bitfield.rs26
-rw-r--r--tests/expectations/tests/derive-partialeq-union.rs10
-rw-r--r--tests/expectations/tests/derive-partialeq-union_1_0.rs9
-rw-r--r--tests/expectations/tests/divide-by-zero-in-struct-layout.rs23
-rw-r--r--tests/expectations/tests/doggo-or-null.rs9
-rw-r--r--tests/expectations/tests/enum-variant-replaces.rs7
-rw-r--r--tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs9
-rw-r--r--tests/expectations/tests/issue-1034.rs23
-rw-r--r--tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs23
-rw-r--r--tests/expectations/tests/issue-537.rs10
-rw-r--r--tests/expectations/tests/issue-648-derive-debug-with-padding.rs10
-rw-r--r--tests/expectations/tests/issue-739-pointer-wide-bitfield.rs23
-rw-r--r--tests/expectations/tests/issue-816.rs23
-rw-r--r--tests/expectations/tests/issue-848-replacement-system-include.rs10
-rw-r--r--tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs9
-rw-r--r--tests/expectations/tests/issue_315.rs10
-rw-r--r--tests/expectations/tests/jsval_layout_opaque.rs23
-rw-r--r--tests/expectations/tests/jsval_layout_opaque_1_0.rs23
-rw-r--r--tests/expectations/tests/layout_align.rs16
-rw-r--r--tests/expectations/tests/layout_cmdline_token.rs7
-rw-r--r--tests/expectations/tests/layout_eth_conf.rs16
-rw-r--r--tests/expectations/tests/layout_eth_conf_1_0.rs16
-rw-r--r--tests/expectations/tests/layout_mbuf.rs16
-rw-r--r--tests/expectations/tests/layout_mbuf_1_0.rs16
-rw-r--r--tests/expectations/tests/libclang-5/type_alias_template_specialized.rs9
-rw-r--r--tests/expectations/tests/no-derive-debug.rs9
-rw-r--r--tests/expectations/tests/no-derive-default.rs9
-rw-r--r--tests/expectations/tests/no_copy.rs10
-rw-r--r--tests/expectations/tests/only_bitfields.rs23
-rw-r--r--tests/expectations/tests/opaque-template-inst-member-2.rs10
-rw-r--r--tests/expectations/tests/opaque-template-inst-member.rs9
-rw-r--r--tests/expectations/tests/opaque_in_struct.rs10
-rw-r--r--tests/expectations/tests/opaque_pointer.rs10
-rw-r--r--tests/expectations/tests/opaque_typedef.rs9
-rw-r--r--tests/expectations/tests/private.rs9
-rw-r--r--tests/expectations/tests/reparented_replacement.rs9
-rw-r--r--tests/expectations/tests/replace_template_alias.rs10
-rw-r--r--tests/expectations/tests/replace_use.rs10
-rw-r--r--tests/expectations/tests/replaces_double.rs9
-rw-r--r--tests/expectations/tests/struct_with_bitfields.rs23
-rw-r--r--tests/expectations/tests/template.rs7
-rw-r--r--tests/expectations/tests/templatized-bitfield.rs10
-rw-r--r--tests/expectations/tests/union_bitfield.rs23
-rw-r--r--tests/expectations/tests/union_bitfield_1_0.rs16
-rw-r--r--tests/expectations/tests/union_with_anon_struct_bitfield.rs23
-rw-r--r--tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs23
-rw-r--r--tests/expectations/tests/weird_bitfields.rs23
-rw-r--r--tests/expectations/tests/zero-sized-array.rs9
-rw-r--r--tests/rustfmt.toml2
89 files changed, 628 insertions, 830 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 49515751..ded2f0b6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -25,8 +25,29 @@ dependencies = [
]
[[package]]
+name = "backtrace"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "backtrace-sys"
+version = "0.1.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "bindgen"
-version = "0.43.2"
+version = "0.44.0"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cexpr 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -38,11 +59,11 @@ dependencies = [
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -110,6 +131,14 @@ dependencies = [
]
[[package]]
+name = "failure"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -177,7 +206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
-version = "0.3.5"
+version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -190,10 +219,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
-version = "0.5.2"
+version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -230,6 +259,11 @@ dependencies = [
]
[[package]]
+name = "rustc-demangle"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -305,9 +339,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "which"
-version = "1.0.5"
+version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
+ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -351,6 +386,8 @@ dependencies = [
"checksum aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "68f56c7353e5a9547cbd76ed90f7bb5ffc3ba09d4ea9bd1d8c06c8b1142eeb5a"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
+"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
+"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cexpr 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8fc0086be9ca82f7fc89fc873435531cb898b86e850005850de1f820e2db6e9b"
@@ -359,6 +396,7 @@ dependencies = [
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
+"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
@@ -368,13 +406,14 @@ dependencies = [
"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b"
"checksum nom 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "898696750eb5c3ce5eb5afbfbe46e7f7c4e1936e19d3e97be4b7937da7b6d114"
"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
-"checksum proc-macro2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "77997c53ae6edd6d187fec07ec41b207063b5ee6f33680e9fa86d405cdd313d4"
+"checksum proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "ffe022fb8c8bd254524b0b3305906c1921fa37a84a644e29079a9e62200c3901"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
-"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
+"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2069749032ea3ec200ca51e4a31df41759190a88edca0d2d86ee8bedf7073341"
"checksum regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "747ba3b235651f6e2f67dfa8bcdcd073ddb7c243cb21c442fc12395dfcac212d"
+"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
"checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
@@ -387,7 +426,7 @@ dependencies = [
"checksum utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd70f467df6810094968e2fce0ee1bd0e87157aceb026a8c083bcf5e25b9efe4"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
-"checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2"
+"checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
diff --git a/Cargo.toml b/Cargo.toml
index 8e8945ca..f1bafdbe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,7 @@ readme = "README.md"
repository = "https://github.com/rust-lang/rust-bindgen"
documentation = "https://docs.rs/bindgen"
homepage = "https://rust-lang.github.io/rust-bindgen/"
-version = "0.43.2"
+version = "0.44.0"
build = "build.rs"
include = [
@@ -51,12 +51,12 @@ clap = "2"
clang-sys = { version = "0.26", features = ["runtime", "clang_6_0"] }
lazy_static = "1"
peeking_take_while = "0.1.2"
-quote = { version = "0.5", default-features = false }
+quote = { version = "0.6", default-features = false }
regex = "1.0"
-which = "1.0.2"
+which = "2.0"
# New validation in 0.3.6 breaks bindgen-integration:
# https://github.com/alexcrichton/proc-macro2/commit/489c642.
-proc-macro2 = { version = "0.3.2, < 0.3.6", default-features = false }
+proc-macro2 = { version = "0.4", default-features = false }
[dependencies.env_logger]
optional = true
diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml
index 126cb363..1cd69b9f 100644
--- a/bindgen-integration/Cargo.toml
+++ b/bindgen-integration/Cargo.toml
@@ -8,7 +8,7 @@ build = "build.rs"
[build-dependencies]
bindgen = { path = ".." }
-gcc = "0.3"
+cc = "1.0"
[features]
testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"]
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index 61580175..d9be232b 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -1,5 +1,5 @@
extern crate bindgen;
-extern crate gcc;
+extern crate cc;
use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks};
use bindgen::Builder;
@@ -72,7 +72,7 @@ impl Drop for MacroCallback {
}
fn main() {
- gcc::Build::new()
+ cc::Build::new()
.cpp(true)
.file("cpp/Test.cc")
.compile("libtest.a");
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 02909d57..aea4b1fb 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -2,58 +2,54 @@
use ir::context::BindgenContext;
use ir::layout::Layout;
-use quote;
-use proc_macro2::{Term, Span};
+use proc_macro2::{self, Ident, Span};
+use quote::TokenStreamExt;
pub mod attributes {
- use quote;
- use proc_macro2::{Term, Span};
+ use proc_macro2::{self, Ident, Span};
- pub fn repr(which: &str) -> quote::Tokens {
- let which = Term::new(which, Span::call_site());
+ pub fn repr(which: &str) -> proc_macro2::TokenStream {
+ let which = Ident::new(which, Span::call_site());
quote! {
#[repr( #which )]
}
}
- pub fn repr_list(which_ones: &[&str]) -> quote::Tokens {
- let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site()));
+ pub fn repr_list(which_ones: &[&str]) -> proc_macro2::TokenStream {
+ let which_ones = which_ones.iter().cloned().map(|one| Ident::new(one, Span::call_site()));
quote! {
#[repr( #( #which_ones ),* )]
}
}
- pub fn derives(which_ones: &[&str]) -> quote::Tokens {
- let which_ones = which_ones.iter().cloned().map(|one| Term::new(one, Span::call_site()));
+ pub fn derives(which_ones: &[&str]) -> proc_macro2::TokenStream {
+ let which_ones = which_ones.iter().cloned().map(|one| Ident::new(one, Span::call_site()));
quote! {
#[derive( #( #which_ones ),* )]
}
}
- pub fn inline() -> quote::Tokens {
+ pub fn inline() -> proc_macro2::TokenStream {
quote! {
#[inline]
}
}
- pub fn must_use() -> quote::Tokens {
+ pub fn must_use() -> proc_macro2::TokenStream {
quote! {
#[must_use]
}
}
- pub fn doc(comment: String) -> quote::Tokens {
- // Doc comments are already preprocessed into nice `///` formats by the
- // time they get here. Just make sure that we have newlines around it so
- // that nothing else gets wrapped into the comment.
- let mut tokens = quote! {};
- tokens.append(Term::new("\n", Span::call_site()));
- tokens.append(Term::new(&comment, Span::call_site()));
- tokens.append(Term::new("\n", Span::call_site()));
- tokens
+ pub fn doc(comment: String) -> proc_macro2::TokenStream {
+ use std::str::FromStr;
+
+ // NOTE(emilio): By this point comments are already preprocessed and in
+ // `///` form. Quote turns them into `#[doc]` comments, but oh well.
+ proc_macro2::TokenStream::from_str(&comment).unwrap()
}
- pub fn link_name(name: &str) -> quote::Tokens {
+ pub fn link_name(name: &str) -> proc_macro2::TokenStream {
// LLVM mangles the name by default but it's already mangled.
// Prefixing the name with \u{1} should tell LLVM to not mangle it.
let name = format!("\u{1}{}", name);
@@ -65,7 +61,7 @@ pub mod attributes {
/// Generates a proper type for a field or type with a given `Layout`, that is,
/// a type with the correct size and alignment restrictions.
-pub fn blob(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
+pub fn blob(ctx: &BindgenContext, layout: Layout) -> proc_macro2::TokenStream {
let opaque = layout.opaque();
// FIXME(emilio, #412): We fall back to byte alignment, but there are
@@ -80,7 +76,7 @@ pub fn blob(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
}
};
- let ty_name = Term::new(ty_name, Span::call_site());
+ let ty_name = Ident::new(ty_name, Span::call_site());
let data_len = opaque.array_size(ctx).unwrap_or(layout.size);
@@ -96,14 +92,14 @@ pub fn blob(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
}
/// Integer type of the same size as the given `Layout`.
-pub fn integer_type(ctx: &BindgenContext, layout: Layout) -> Option<quote::Tokens> {
+pub fn integer_type(ctx: &BindgenContext, layout: Layout) -> Option<proc_macro2::TokenStream> {
let name = Layout::known_type_for_size(ctx, layout.size)?;
- let name = Term::new(name, Span::call_site());
+ let name = Ident::new(name, Span::call_site());
Some(quote! { #name })
}
/// Generates a bitfield allocation unit type for a type with the given `Layout`.
-pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> quote::Tokens {
+pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> proc_macro2::TokenStream {
let mut tokens = quote! {};
if ctx.options().enable_cxx_namespaces {
@@ -130,10 +126,9 @@ pub mod ast_ty {
use ir::function::FunctionSig;
use ir::layout::Layout;
use ir::ty::FloatKind;
- use quote;
use proc_macro2;
- pub fn raw_type(ctx: &BindgenContext, name: &str) -> quote::Tokens {
+ pub fn raw_type(ctx: &BindgenContext, name: &str) -> proc_macro2::TokenStream {
let ident = ctx.rust_ident_raw(name);
match ctx.options().ctypes_prefix {
Some(ref prefix) => {
@@ -152,7 +147,7 @@ pub mod ast_ty {
ctx: &BindgenContext,
fk: FloatKind,
layout: Option<Layout>,
- ) -> quote::Tokens {
+ ) -> proc_macro2::TokenStream {
// TODO: we probably should take the type layout into account more
// often?
//
@@ -192,25 +187,25 @@ pub mod ast_ty {
}
}
- pub fn int_expr(val: i64) -> quote::Tokens {
+ pub fn int_expr(val: i64) -> proc_macro2::TokenStream {
// Don't use quote! { #val } because that adds the type suffix.
let val = proc_macro2::Literal::i64_unsuffixed(val);
quote!(#val)
}
- pub fn uint_expr(val: u64) -> quote::Tokens {
+ pub fn uint_expr(val: u64) -> proc_macro2::TokenStream {
// Don't use quote! { #val } because that adds the type suffix.
let val = proc_macro2::Literal::u64_unsuffixed(val);
quote!(#val)
}
- pub fn byte_array_expr(bytes: &[u8]) -> quote::Tokens {
+ pub fn byte_array_expr(bytes: &[u8]) -> proc_macro2::TokenStream {
let mut bytes: Vec<_> = bytes.iter().cloned().collect();
bytes.push(0);
quote! { [ #(#bytes),* ] }
}
- pub fn cstr_expr(mut string: String) -> quote::Tokens {
+ pub fn cstr_expr(mut string: String) -> proc_macro2::TokenStream {
string.push('\0');
let b = proc_macro2::Literal::byte_string(&string.as_bytes());
quote! {
@@ -221,7 +216,7 @@ pub mod ast_ty {
pub fn float_expr(
ctx: &BindgenContext,
f: f64,
- ) -> Result<quote::Tokens, ()> {
+ ) -> Result<proc_macro2::TokenStream, ()> {
if f.is_finite() {
let val = proc_macro2::Literal::f64_unsuffixed(f);
@@ -255,7 +250,7 @@ pub mod ast_ty {
pub fn arguments_from_signature(
signature: &FunctionSig,
ctx: &BindgenContext,
- ) -> Vec<quote::Tokens> {
+ ) -> Vec<proc_macro2::TokenStream> {
let mut unnamed_arguments = 0;
signature
.argument_types()
diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs
index 8759bf27..d429e328 100644
--- a/src/codegen/impl_debug.rs
+++ b/src/codegen/impl_debug.rs
@@ -3,14 +3,14 @@ use ir::context::BindgenContext;
use ir::derive::CanTriviallyDeriveDebug;
use ir::item::{HasTypeParamInArray, IsOpaque, Item, ItemCanonicalName};
use ir::ty::{RUST_DERIVE_IN_ARRAY_LIMIT, TypeKind};
-use quote;
+use proc_macro2;
pub fn gen_debug_impl(
ctx: &BindgenContext,
fields: &[Field],
item: &Item,
kind: CompKind,
-) -> quote::Tokens {
+) -> proc_macro2::TokenStream {
let struct_name = item.canonical_name(ctx);
let mut format_string = format!("{} {{{{ ", struct_name);
let mut tokens = vec![];
@@ -63,7 +63,7 @@ pub trait ImplDebug<'a> {
&self,
ctx: &BindgenContext,
extra: Self::Extra,
- ) -> Option<(String, Vec<quote::Tokens>)>;
+ ) -> Option<(String, Vec<proc_macro2::TokenStream>)>;
}
impl<'a> ImplDebug<'a> for FieldData {
@@ -73,7 +73,7 @@ impl<'a> ImplDebug<'a> for FieldData {
&self,
ctx: &BindgenContext,
_: Self::Extra,
- ) -> Option<(String, Vec<quote::Tokens>)> {
+ ) -> Option<(String, Vec<proc_macro2::TokenStream>)> {
if let Some(name) = self.name() {
ctx.resolve_item(self.ty()).impl_debug(ctx, name)
} else {
@@ -89,7 +89,7 @@ impl<'a> ImplDebug<'a> for BitfieldUnit {
&self,
ctx: &BindgenContext,
_: Self::Extra,
- ) -> Option<(String, Vec<quote::Tokens>)> {
+ ) -> Option<(String, Vec<proc_macro2::TokenStream>)> {
let mut format_string = String::new();
let mut tokens = vec![];
for (i, bitfield) in self.bitfields().iter().enumerate() {
@@ -118,7 +118,7 @@ impl<'a> ImplDebug<'a> for Item {
&self,
ctx: &BindgenContext,
name: &str,
- ) -> Option<(String, Vec<quote::Tokens>)> {
+ ) -> Option<(String, Vec<proc_macro2::TokenStream>)> {
let name_ident = ctx.rust_ident(name);
// We don't know if blacklisted items `impl Debug` or not, so we can't
@@ -136,8 +136,8 @@ impl<'a> ImplDebug<'a> for Item {
fn debug_print(
name: &str,
- name_ident: quote::Tokens,
- ) -> Option<(String, Vec<quote::Tokens>)> {
+ name_ident: proc_macro2::TokenStream,
+ ) -> Option<(String, Vec<proc_macro2::TokenStream>)> {
Some((
format!("{}: {{:?}}", name),
vec![quote! {
diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs
index c8ff6313..ca61b4bf 100644
--- a/src/codegen/impl_partialeq.rs
+++ b/src/codegen/impl_partialeq.rs
@@ -3,7 +3,6 @@ use ir::comp::{CompInfo, CompKind, Field, FieldMethods};
use ir::context::BindgenContext;
use ir::item::{IsOpaque, Item};
use ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT};
-use quote;
use proc_macro2;
/// Generate a manual implementation of `PartialEq` trait for the
@@ -12,8 +11,8 @@ pub fn gen_partialeq_impl(
ctx: &BindgenContext,
comp_info: &CompInfo,
item: &Item,
- ty_for_impl: &quote::Tokens,
-) -> Option<quote::Tokens> {
+ ty_for_impl: &proc_macro2::TokenStream,
+) -> Option<proc_macro2::TokenStream> {
let mut tokens = vec![];
if item.is_opaque(ctx, &()) {
@@ -71,8 +70,8 @@ pub fn gen_partialeq_impl(
})
}
-fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> quote::Tokens {
- fn quote_equals(name_ident: proc_macro2::Term) -> quote::Tokens {
+fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> proc_macro2::TokenStream {
+ fn quote_equals(name_ident: proc_macro2::Ident) -> proc_macro2::TokenStream {
quote! { self.#name_ident == other.#name_ident }
}
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 9405f11b..d2b77d6a 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -37,8 +37,8 @@ use ir::template::{AsTemplateParam, TemplateInstantiation, TemplateParameters};
use ir::ty::{Type, TypeKind};
use ir::var::Var;
-use quote;
-use proc_macro2::{self, Term, Span};
+use quote::TokenStreamExt;
+use proc_macro2::{self, Ident, Span};
use std;
use std::borrow::Cow;
@@ -48,11 +48,12 @@ use std::collections::hash_map::{Entry, HashMap};
use std::fmt::Write;
use std::iter;
use std::ops;
+use std::str::FromStr;
// Name of type defined in constified enum module
pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &'static str = "Type";
-fn top_level_path(ctx: &BindgenContext, item: &Item) -> Vec<quote::Tokens> {
+fn top_level_path(ctx: &BindgenContext, item: &Item) -> Vec<proc_macro2::TokenStream> {
let mut path = vec![quote! { self }];
if ctx.options().enable_cxx_namespaces {
@@ -64,7 +65,7 @@ fn top_level_path(ctx: &BindgenContext, item: &Item) -> Vec<quote::Tokens> {
path
}
-fn root_import(ctx: &BindgenContext, module: &Item) -> quote::Tokens {
+fn root_import(ctx: &BindgenContext, module: &Item) -> proc_macro2::TokenStream {
assert!(ctx.options().enable_cxx_namespaces, "Somebody messed it up");
assert!(module.is_module());
@@ -76,7 +77,7 @@ fn root_import(ctx: &BindgenContext, module: &Item) -> quote::Tokens {
let mut tokens = quote! {};
- tokens.append_separated(path, Term::new("::", Span::call_site()));
+ tokens.append_separated(path, quote!(::));
quote! {
#[allow(unused_imports)]
@@ -85,7 +86,7 @@ fn root_import(ctx: &BindgenContext, module: &Item) -> quote::Tokens {
}
struct CodegenResult<'a> {
- items: Vec<quote::Tokens>,
+ items: Vec<proc_macro2::TokenStream>,
/// A monotonic counter used to add stable unique id's to stuff that doesn't
/// need to be referenced by anything.
@@ -212,7 +213,7 @@ impl<'a> CodegenResult<'a> {
self.vars_seen.insert(name.into());
}
- fn inner<F>(&mut self, cb: F) -> Vec<quote::Tokens>
+ fn inner<F>(&mut self, cb: F) -> Vec<proc_macro2::TokenStream>
where
F: FnOnce(&mut Self),
{
@@ -231,7 +232,7 @@ impl<'a> CodegenResult<'a> {
}
impl<'a> ops::Deref for CodegenResult<'a> {
- type Target = Vec<quote::Tokens>;
+ type Target = Vec<proc_macro2::TokenStream>;
fn deref(&self) -> &Self::Target {
&self.items
@@ -247,11 +248,11 @@ impl<'a> ops::DerefMut for CodegenResult<'a> {
/// A trait to convert a rust type into a pointer, optionally const, to the same
/// type.
trait ToPtr {
- fn to_ptr(self, is_const: bool) -> quote::Tokens;
+ fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream;
}
-impl ToPtr for quote::Tokens {
- fn to_ptr(self, is_const: bool) -> quote::Tokens {
+impl ToPtr for proc_macro2::TokenStream {
+ fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream {
if is_const {
quote! { *const #self }
} else {
@@ -260,7 +261,7 @@ impl ToPtr for quote::Tokens {
}
}
-/// An extension trait for `quote::Tokens` that lets us append any implicit
+/// An extension trait for `proc_macro2::TokenStream` that lets us append any implicit
/// template parameters that exist for some type, if necessary.
trait AppendImplicitTemplateParams {
fn append_implicit_template_params(
@@ -270,7 +271,7 @@ trait AppendImplicitTemplateParams {
);
}
-impl AppendImplicitTemplateParams for quote::Tokens {
+impl AppendImplicitTemplateParams for proc_macro2::TokenStream {
fn append_implicit_template_params(
&mut self,
ctx: &BindgenContext,
@@ -439,10 +440,7 @@ impl CodeGenerator for Module {
if let Some(raw_lines) = ctx.options().module_lines.get(&path) {
for raw_line in raw_lines {
found_any = true;
- // FIXME(emilio): The use of `Term` is an abuse, but we abuse it
- // in a bunch more places.
- let line = Term::new(raw_line, Span::call_site());
- result.push(quote! { #line });
+ result.push(proc_macro2::TokenStream::from_str(raw_line).unwrap());
}
}
@@ -756,7 +754,7 @@ impl CodeGenerator for Type {
pub use
});
let path = top_level_path(ctx, item);
- tokens.append_separated(path, Term::new("::", Span::call_site()));
+ tokens.append_separated(path, quote!(::));
tokens.append_all(quote! {
:: #inner_rust_type as #rust_name ;
});
@@ -868,7 +866,7 @@ impl<'a> TryToRustTy for Vtable<'a> {
&self,
ctx: &BindgenContext,
_: &(),
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
let name = ctx.rust_ident(self.canonical_name(ctx));
Ok(quote! {
#name
@@ -963,8 +961,8 @@ trait FieldCodegen<'a> {
methods: &mut M,
extra: Self::Extra,
) where
- F: Extend<quote::Tokens>,
- M: Extend<quote::Tokens>;
+ F: Extend<proc_macro2::TokenStream>,
+ M: Extend<proc_macro2::TokenStream>;
}
impl<'a> FieldCodegen<'a> for Field {
@@ -983,8 +981,8 @@ impl<'a> FieldCodegen<'a> for Field {
methods: &mut M,
_: (),
) where
- F: Extend<quote::Tokens>,
- M: Extend<quote::Tokens>,
+ F: Extend<proc_macro2::TokenStream>,
+ M: Extend<proc_macro2::TokenStream>,
{
match *self {
Field::DataMember(ref data) => {
@@ -1035,8 +1033,8 @@ impl<'a> FieldCodegen<'a> for FieldData {
methods: &mut M,
_: (),
) where
- F: Extend<quote::Tokens>,
- M: Extend<quote::Tokens>,
+ F: Extend<proc_macro2::TokenStream>,
+ M: Extend<proc_macro2::TokenStream>,
{
// Bitfields are handled by `FieldCodegen` implementations for
// `BitfieldUnit` and `Bitfield`.
@@ -1170,8 +1168,8 @@ impl<'a> FieldCodegen<'a> for FieldData {
impl BitfieldUnit {
/// Get the constructor name for this bitfield unit.
- fn ctor_name(&self) -> quote::Tokens {
- let ctor_name = Term::new(&format!("new_bitfield_{}", self.nth()), Span::call_site());
+ fn ctor_name(&self) -> proc_macro2::TokenStream {
+ let ctor_name = Ident::new(&format!("new_bitfield_{}", self.nth()), Span::call_site());
quote! {
#ctor_name
}
@@ -1189,9 +1187,9 @@ impl Bitfield {
fn extend_ctor_impl(
&self,
ctx: &BindgenContext,
- param_name: quote::Tokens,
- mut ctor_impl: quote::Tokens,
- ) -> quote::Tokens {
+ param_name: proc_macro2::TokenStream,
+ mut ctor_impl: proc_macro2::TokenStream,
+ ) -> proc_macro2::TokenStream {
let bitfield_ty = ctx.resolve_type(self.ty());
let bitfield_ty_layout = bitfield_ty.layout(ctx).expect(
"Bitfield without layout? Gah!",
@@ -1235,8 +1233,8 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
methods: &mut M,
_: (),
) where
- F: Extend<quote::Tokens>,
- M: Extend<quote::Tokens>,
+ F: Extend<proc_macro2::TokenStream>,
+ M: Extend<proc_macro2::TokenStream>,
{
result.saw_bitfield_unit();
@@ -1333,7 +1331,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit {
fn bitfield_getter_name(
ctx: &BindgenContext,
bitfield: &Bitfield,
-) -> quote::Tokens {
+) -> proc_macro2::TokenStream {
let name = bitfield.getter_name();
let name = ctx.rust_ident_raw(name);
quote! { #name }
@@ -1342,7 +1340,7 @@ fn bitfield_getter_name(
fn bitfield_setter_name(
ctx: &BindgenContext,
bitfield: &Bitfield,
-) -> quote::Tokens {
+) -> proc_macro2::TokenStream {
let setter = bitfield.setter_name();
let setter = ctx.rust_ident_raw(setter);
quote! { #setter }
@@ -1364,13 +1362,13 @@ impl<'a> FieldCodegen<'a> for Bitfield {
methods: &mut M,
(unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool),
) where
- F: Extend<quote::Tokens>,
- M: Extend<quote::Tokens>,
+ F: Extend<proc_macro2::TokenStream>,
+ M: Extend<proc_macro2::TokenStream>,
{
let prefix = ctx.trait_prefix();
let getter_name = bitfield_getter_name(ctx, self);
let setter_name = bitfield_setter_name(ctx, self);
- let unit_field_ident = Term::new(unit_field_name, Span::call_site());
+ let unit_field_ident = Ident::new(unit_field_name, Span::call_site());
let bitfield_ty_item = ctx.resolve_item(self.ty());
let bitfield_ty = bitfield_ty_item.expect_type();
@@ -1805,7 +1803,7 @@ impl CodeGenerator for CompInfo {
if self.found_unknown_attr() {
warn!(
"Type {} has an unknown attribute that may affect layout",
- canonical_ident.as_str()
+ canonical_ident
);
}
@@ -1819,7 +1817,7 @@ impl CodeGenerator for CompInfo {
if ctx.options().layout_tests && !self.is_forward_declaration() {
if let Some(layout) = layout {
let fn_name =
- format!("bindgen_test_layout_{}", canonical_ident.as_str());
+ format!("bindgen_test_layout_{}", canonical_ident);
let fn_name = ctx.rust_ident_raw(fn_name);
let prefix = ctx.trait_prefix();
let size_of_expr = quote! {
@@ -1881,7 +1879,7 @@ impl CodeGenerator for CompInfo {
})
})
})
- .collect::<Vec<quote::Tokens>>();
+ .collect::<Vec<proc_macro2::TokenStream>>();
asserts
};
@@ -2021,7 +2019,7 @@ trait MethodCodegen {
fn codegen_method<'a>(
&self,
ctx: &BindgenContext,
- methods: &mut Vec<quote::Tokens>,
+ methods: &mut Vec<proc_macro2::TokenStream>,
method_names: &mut HashMap<String, usize>,
result: &mut CodegenResult<'a>,
parent: &CompInfo,
@@ -2032,7 +2030,7 @@ impl MethodCodegen for Method {
fn codegen_method<'a>(
&self,
ctx: &BindgenContext,
- methods: &mut Vec<quote::Tokens>,
+ methods: &mut Vec<proc_macro2::TokenStream>,
method_names: &mut HashMap<String, usize>,
result: &mut CodegenResult<'a>,
_parent: &CompInfo,
@@ -2237,24 +2235,24 @@ impl std::str::FromStr for EnumVariation {
enum EnumBuilder<'a> {
Rust {
codegen_depth: usize,
- attrs: Vec<quote::Tokens>,
- ident: Term,
- tokens: quote::Tokens,
+ attrs: Vec<proc_macro2::TokenStream>,
+ ident: Ident,
+ tokens: proc_macro2::TokenStream,
emitted_any_variants: bool,
},
Bitfield {
codegen_depth: usize,
canonical_name: &'a str,
- tokens: quote::Tokens,
+ tokens: proc_macro2::TokenStream,
},
Consts {
- variants: Vec<quote::Tokens>,
+ variants: Vec<proc_macro2::TokenStream>,
codegen_depth: usize,
},
ModuleConsts {
codegen_depth: usize,
module_name: &'a str,
- module_items: Vec<quote::Tokens>,
+ module_items: Vec<proc_macro2::TokenStream>,
},
}
@@ -2273,12 +2271,12 @@ impl<'a> EnumBuilder<'a> {
/// the representation, and which variation it should be generated as.
fn new(
name: &'a str,
- attrs: Vec<quote::Tokens>,
- repr: quote::Tokens,
+ attrs: Vec<proc_macro2::TokenStream>,
+ repr: proc_macro2::TokenStream,
enum_variation: EnumVariation,
enum_codegen_depth: usize,
) -> Self {
- let ident = Term::new(name, Span::call_site());
+ let ident = Ident::new(name, Span::call_site());
match enum_variation {
EnumVariation::Bitfield => {
@@ -2316,7 +2314,7 @@ impl<'a> EnumBuilder<'a> {
}
EnumVariation::ModuleConsts => {
- let ident = Term::new(CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site());
+ let ident = Ident::new(CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site());
let type_definition = quote! {
#( #attrs )*
pub type #ident = #repr;
@@ -2337,7 +2335,7 @@ impl<'a> EnumBuilder<'a> {
ctx: &BindgenContext,
variant: &EnumVariant,
mangling_prefix: Option<&str>,
- rust_ty: quote::Tokens,
+ rust_ty: proc_macro2::TokenStream,
result: &mut CodegenResult<'b>,
is_ty_named: bool,
) -> Self {
@@ -2439,9 +2437,9 @@ impl<'a> EnumBuilder<'a> {
fn build<'b>(
self,
ctx: &BindgenContext,
- rust_ty: quote::Tokens,
+ rust_ty: proc_macro2::TokenStream,
result: &mut CodegenResult<'b>,
- ) -> quote::Tokens {
+ ) -> proc_macro2::TokenStream {
match self {
EnumBuilder::Rust { attrs, ident, tokens, emitted_any_variants, .. } => {
let variants = if !emitted_any_variants {
@@ -2612,23 +2610,23 @@ impl CodeGenerator for Enum {
ctx: &BindgenContext,
enum_: &Type,
// Only to avoid recomputing every time.
- enum_canonical_name: &Term,
+ enum_canonical_name: &Ident,
// May be the same as "variant" if it's because the
// enum is unnamed and we still haven't seen the
// value.
- variant_name: &str,
- referenced_name: &Term,
- enum_rust_ty: quote::Tokens,
+ variant_name: &Ident,
+ referenced_name: &Ident,
+ enum_rust_ty: proc_macro2::TokenStream,
result: &mut CodegenResult<'a>,
) {
let constant_name = if enum_.name().is_some() {
if ctx.options().prepend_enum_name {
- format!("{}_{}", enum_canonical_name.as_str(), variant_name)
+ format!("{}_{}", enum_canonical_name, variant_name)
} else {
- variant_name.into()
+ format!("{}", variant_name)
}
} else {
- variant_name.into()
+ format!("{}", variant_name)
};
let constant_name = ctx.rust_ident(constant_name);
@@ -2652,7 +2650,7 @@ impl CodeGenerator for Enum {
);
// A map where we keep a value -> variant relation.
- let mut seen_values = HashMap::<_, Term>::new();
+ let mut seen_values = HashMap::<_, Ident>::new();
let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &());
let is_toplevel = item.is_toplevel(ctx);
@@ -2724,7 +2722,7 @@ impl CodeGenerator for Enum {
ctx,
enum_ty,
&ident,
- &*mangled_name,
+ &Ident::new(&*mangled_name, Span::call_site()),
existing_variant_name,
enum_rust_ty.clone(),
result,
@@ -2765,11 +2763,11 @@ impl CodeGenerator for Enum {
let parent_name =
parent_canonical_name.as_ref().unwrap();
- Term::new(
+ Ident::new(
&format!(
"{}_{}",
parent_name,
- variant_name.as_str()
+ variant_name
),
Span::call_site()
)
@@ -2779,7 +2777,7 @@ impl CodeGenerator for Enum {
ctx,
enum_ty,
&ident,
- mangled_name.as_str(),
+ &mangled_name,
&variant_name,
enum_rust_ty.clone(),
result,
@@ -2816,7 +2814,7 @@ trait TryToOpaque {
&self,
ctx: &BindgenContext,
extra: &Self::Extra,
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
self.try_get_layout(ctx, extra).map(|layout| {
helpers::blob(ctx, layout)
})
@@ -2843,7 +2841,7 @@ trait ToOpaque: TryToOpaque {
&self,
ctx: &BindgenContext,
extra: &Self::Extra,
- ) -> quote::Tokens {
+ ) -> proc_macro2::TokenStream {
let layout = self.get_layout(ctx, extra);
helpers::blob(ctx, layout)
}
@@ -2869,7 +2867,7 @@ trait TryToRustTy {
&self,
ctx: &BindgenContext,
extra: &Self::Extra,
- ) -> error::Result<quote::Tokens>;
+ ) -> error::Result<proc_macro2::TokenStream>;
}
/// Fallible conversion to a Rust type or an opaque blob with the correct size
@@ -2884,7 +2882,7 @@ trait TryToRustTyOrOpaque: TryToRustTy + TryToOpaque {
&self,
ctx: &BindgenContext,
extra: &<Self as TryToRustTyOrOpaque>::Extra,
- ) -> error::Result<quote::Tokens>;
+ ) -> error::Result<proc_macro2::TokenStream>;
}
impl<E, T> TryToRustTyOrOpaque for T
@@ -2898,7 +2896,7 @@ where
&self,
ctx: &BindgenContext,
extra: &E,
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
self.try_to_rust_ty(ctx, extra).or_else(
|_| if let Ok(layout) =
self.try_get_layout(ctx, extra)
@@ -2935,7 +2933,7 @@ trait ToRustTyOrOpaque: TryToRustTy + ToOpaque {
&self,
ctx: &BindgenContext,
extra: &<Self as ToRustTyOrOpaque>::Extra,
- ) -> quote::Tokens;
+ ) -> proc_macro2::TokenStream;
}
impl<E, T> ToRustTyOrOpaque for T
@@ -2948,7 +2946,7 @@ where
&self,
ctx: &BindgenContext,
extra: &E,
- ) -> quote::Tokens {
+ ) -> proc_macro2::TokenStream {
self.try_to_rust_ty(ctx, extra).unwrap_or_else(|_| {
self.to_opaque(ctx, extra)
})
@@ -2980,7 +2978,7 @@ where
&self,
ctx: &BindgenContext,
_: &(),
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
ctx.resolve_item((*self).into()).try_to_rust_ty(ctx, &())
}
}
@@ -3004,7 +3002,7 @@ impl TryToRustTy for Item {
&self,
ctx: &BindgenContext,
_: &(),
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
self.kind().expect_type().try_to_rust_ty(ctx, self)
}
}
@@ -3028,7 +3026,7 @@ impl TryToRustTy for Type {
&self,
ctx: &BindgenContext,
item: &Item,
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
use self::helpers::ast_ty::*;
match *self.kind() {
@@ -3130,7 +3128,7 @@ impl TryToRustTy for Type {
}
TypeKind::Enum(..) => {
let path = item.namespace_aware_canonical_path(ctx);
- let path = Term::new(&path.join("::"), Span::call_site());
+ let path = proc_macro2::TokenStream::from_str(&path.join("::")).unwrap();
Ok(quote!(#path))
}
TypeKind::TemplateInstantiation(ref inst) => {
@@ -3233,7 +3231,7 @@ impl TryToRustTy for TemplateInstantiation {
&self,
ctx: &BindgenContext,
item: &Item,
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
if self.is_opaque(ctx, item) {
return Err(error::Error::InstantiationOfOpaqueType);
}
@@ -3245,7 +3243,7 @@ impl TryToRustTy for TemplateInstantiation {
let mut ty = quote! {};
let def_path = def.namespace_aware_canonical_path(ctx);
- ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), Term::new("::", Span::call_site()));
+ ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), quote!(::));
let def_params = def.self_template_params(ctx);
if def_params.is_empty() {
@@ -3297,7 +3295,7 @@ impl TryToRustTy for FunctionSig {
&self,
ctx: &BindgenContext,
_: &(),
- ) -> error::Result<quote::Tokens> {
+ ) -> error::Result<proc_macro2::TokenStream> {
// TODO: we might want to consider ignoring the reference return value.
let ret = utils::fnsig_return_ty(ctx, &self);
let arguments = utils::fnsig_arguments(ctx, &self);
@@ -3306,7 +3304,7 @@ impl TryToRustTy for FunctionSig {
match abi {
Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
- Ok(quote::Tokens::new())
+ Ok(proc_macro2::TokenStream::new())
}
_ => {
Ok(quote! {
@@ -3438,7 +3436,7 @@ fn objc_method_codegen(
method: &ObjCMethod,
class_name: Option<&str>,
prefix: &str,
-) -> (quote::Tokens, quote::Tokens) {
+) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) {
let signature = method.signature();
let fn_args = utils::fnsig_arguments(ctx, signature);
let fn_ret = utils::fnsig_return_ty(ctx, signature);
@@ -3552,7 +3550,7 @@ impl CodeGenerator for ObjCInterface {
}
}
-pub(crate) fn codegen(context: BindgenContext) -> (Vec<quote::Tokens>, BindgenOptions) {
+pub(crate) fn codegen(context: BindgenContext) -> (Vec<proc_macro2::TokenStream>, BindgenOptions) {
context.gen(|context| {
let _t = context.timer("codegen");
let counter = Cell::new(0);
@@ -3588,12 +3586,12 @@ mod utils {
use ir::function::FunctionSig;
use ir::item::{Item, ItemCanonicalPath};
use ir::ty::TypeKind;
- use quote;
- use proc_macro2::{Term, Span};
+ use proc_macro2;
use std::mem;
+ use std::str::FromStr;
- pub fn prepend_bitfield_unit_type(result: &mut Vec<quote::Tokens>) {
- let bitfield_unit_type = Term::new(include_str!("./bitfield_unit.rs"), Span::call_site());
+ pub fn prepend_bitfield_unit_type(result: &mut Vec<proc_macro2::TokenStream>) {
+ let bitfield_unit_type = proc_macro2::TokenStream::from_str(include_str!("./bitfield_unit.rs")).unwrap();
let bitfield_unit_type = quote!(#bitfield_unit_type);
let items = vec![bitfield_unit_type];
@@ -3603,7 +3601,7 @@ mod utils {
pub fn prepend_objc_header(
ctx: &BindgenContext,
- result: &mut Vec<quote::Tokens>,
+ result: &mut Vec<proc_macro2::TokenStream>,
) {
let use_objc = if ctx.options().objc_extern_crate {
quote! {
@@ -3628,7 +3626,7 @@ mod utils {
pub fn prepend_block_header(
ctx: &BindgenContext,
- result: &mut Vec<quote::Tokens>,
+ result: &mut Vec<proc_macro2::TokenStream>,
) {
let use_block = if ctx.options().block_extern_crate {
quote! {
@@ -3647,7 +3645,7 @@ mod utils {
pub fn prepend_union_types(
ctx: &BindgenContext,
- result: &mut Vec<quote::Tokens>,
+ result: &mut Vec<proc_macro2::TokenStream>,
) {
let prefix = ctx.trait_prefix();
@@ -3746,7 +3744,7 @@ mod utils {
pub fn prepend_incomplete_array_types(
ctx: &BindgenContext,
- result: &mut Vec<quote::Tokens>,
+ result: &mut Vec<proc_macro2::TokenStream>,
) {
let prefix = ctx.trait_prefix();
@@ -3819,7 +3817,7 @@ mod utils {
}
pub fn prepend_complex_type(
- result: &mut Vec<quote::Tokens>,
+ result: &mut Vec<proc_macro2::TokenStream>,
) {
let complex_type = quote! {
#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)]
@@ -3838,18 +3836,14 @@ mod utils {
pub fn build_path(
item: &Item,
ctx: &BindgenContext,
- ) -> error::Result<quote::Tokens> {
- use proc_macro2::{Term, Span};
-
+ ) -> error::Result<proc_macro2::TokenStream> {
let path = item.namespace_aware_canonical_path(ctx);
- let path = Term::new(&path.join("::"), Span::call_site());
- let tokens = quote! {#path};
- //tokens.append_separated(path, "::");
+ let tokens = proc_macro2::TokenStream::from_str(&path.join("::")).unwrap();
Ok(tokens)
}
- fn primitive_ty(ctx: &BindgenContext, name: &str) -> quote::Tokens {
+ fn primitive_ty(ctx: &BindgenContext, name: &str) -> proc_macro2::TokenStream {
let ident = ctx.rust_ident_raw(name);
quote! {
#ident
@@ -3859,7 +3853,7 @@ mod utils {
pub fn type_from_named(
ctx: &BindgenContext,
name: &str,
- ) -> Option<quote::Tokens> {
+ ) -> Option<proc_macro2::TokenStream> {
// FIXME: We could use the inner item to check this is really a
// primitive type but, who the heck overrides these anyway?
Some(match name {
@@ -3882,7 +3876,7 @@ mod utils {
pub fn fnsig_return_ty(
ctx: &BindgenContext,
sig: &FunctionSig,
- ) -> quote::Tokens {
+ ) -> proc_macro2::TokenStream {
let return_item = ctx.resolve_item(sig.return_type());
if let TypeKind::Void = *return_item.kind().expect_type().kind() {
quote! { }
@@ -3897,7 +3891,7 @@ mod utils {
pub fn fnsig_arguments(
ctx: &BindgenContext,
sig: &FunctionSig,
- ) -> Vec<quote::Tokens> {
+ ) -> Vec<proc_macro2::TokenStream> {
use super::ToPtr;
let mut unnamed_arguments = 0;
@@ -3960,7 +3954,7 @@ mod utils {
pub fn fnsig_block(
ctx: &BindgenContext,
sig: &FunctionSig,
- ) -> quote::Tokens {
+ ) -> proc_macro2::TokenStream {
let args = sig.argument_types().iter().map(|&(_, ty)| {
let arg_item = ctx.resolve_item(ty);
diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs
index 0ea23ddf..921ab215 100644
--- a/src/codegen/struct_layout.rs
+++ b/src/codegen/struct_layout.rs
@@ -6,8 +6,7 @@ use ir::comp::CompInfo;
use ir::context::BindgenContext;
use ir::layout::Layout;
use ir::ty::{Type, TypeKind};
-use quote;
-use proc_macro2::{Term, Span};
+use proc_macro2::{self, Ident, Span};
use std::cmp;
/// Trace the layout of struct.
@@ -154,7 +153,7 @@ impl<'a> StructLayoutTracker<'a> {
field_name: &str,
field_ty: &Type,
field_offset: Option<usize>,
- ) -> Option<quote::Tokens> {
+ ) -> Option<proc_macro2::TokenStream> {
let mut field_layout = field_ty.layout(self.ctx)?;
if let TypeKind::Array(inner, len) =
@@ -236,7 +235,7 @@ impl<'a> StructLayoutTracker<'a> {
padding_layout.map(|layout| self.padding_field(layout))
}
- pub fn pad_struct(&mut self, layout: Layout) -> Option<quote::Tokens> {
+ pub fn pad_struct(&mut self, layout: Layout) -> Option<proc_macro2::TokenStream> {
debug!(
"pad_struct:\n\tself = {:#?}\n\tlayout = {:#?}",
self,
@@ -310,13 +309,13 @@ impl<'a> StructLayoutTracker<'a> {
align_to(self.latest_offset, layout.align) - self.latest_offset
}
- fn padding_field(&mut self, layout: Layout) -> quote::Tokens {
+ fn padding_field(&mut self, layout: Layout) -> proc_macro2::TokenStream {
let ty = helpers::blob(self.ctx, layout);
let padding_count = self.padding_count;
self.padding_count += 1;
- let padding_field_name = Term::new(&format!("__bindgen_padding_{}", padding_count), Span::call_site());
+ let padding_field_name = Ident::new(&format!("__bindgen_padding_{}", padding_count), Span::call_site());
self.max_field_align = cmp::max(self.max_field_align, layout.align);
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 3f49f8a0..063c79f0 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -24,7 +24,7 @@ use cexpr;
use clang::{self, Cursor};
use clang_sys;
use parse::ClangItemParser;
-use proc_macro2::{Term, Span};
+use proc_macro2::{Ident, Span};
use std::borrow::Cow;
use std::cell::Cell;
use std::collections::{HashMap, HashSet, hash_map};
@@ -922,7 +922,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
}
/// Returns a mangled name as a rust identifier.
- pub fn rust_ident<S>(&self, name: S) -> Term
+ pub fn rust_ident<S>(&self, name: S) -> Ident
where
S: AsRef<str>
{
@@ -930,11 +930,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
}
/// Returns a mangled name as a rust identifier.
- pub fn rust_ident_raw<T>(&self, name: T) -> Term
+ pub fn rust_ident_raw<T>(&self, name: T) -> Ident
where
T: AsRef<str>
{
- Term::new(name.as_ref(), Span::call_site())
+ Ident::new(name.as_ref(), Span::call_site())
}
/// Iterate over all items that have been defined.
@@ -2393,7 +2393,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// Convenient method for getting the prefix to use for most traits in
/// codegen depending on the `use_core` option.
- pub fn trait_prefix(&self) -> Term {
+ pub fn trait_prefix(&self) -> Ident {
if self.options().use_core {
self.rust_ident_raw("core")
} else {
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 0b83a74d..f851ad72 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -12,6 +12,8 @@ use ir::derive::{CanTriviallyDeriveDebug, CanTriviallyDeriveHash,
CanTriviallyDerivePartialEqOrPartialOrd, CanDerive};
use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
use quote;
+use quote::TokenStreamExt;
+use proc_macro2;
use std::io;
const RUST_DERIVE_FUNPTR_LIMIT: usize = 12;
@@ -192,7 +194,7 @@ impl Abi {
}
impl quote::ToTokens for Abi {
- fn to_tokens(&self, tokens: &mut quote::Tokens) {
+ fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
tokens.append_all(match *self {
Abi::C => quote! { "C" },
Abi::Stdcall => quote! { "stdcall" },
diff --git a/src/ir/objc.rs b/src/ir/objc.rs
index 46c0802e..61c22356 100644
--- a/src/ir/objc.rs
+++ b/src/ir/objc.rs
@@ -12,8 +12,7 @@ use clang_sys::CXCursor_ObjCClassRef;
use clang_sys::CXCursor_ObjCInstanceMethodDecl;
use clang_sys::CXCursor_ObjCProtocolDecl;
use clang_sys::CXCursor_ObjCProtocolRef;
-use quote;
-use proc_macro2::{Term, Span};
+use proc_macro2::{TokenStream, Ident, Span};
/// Objective C interface as used in TypeKind
///
@@ -213,11 +212,11 @@ impl ObjCMethod {
}
/// Formats the method call
- pub fn format_method_call(&self, args: &[quote::Tokens]) -> quote::Tokens {
+ pub fn format_method_call(&self, args: &[TokenStream]) -> TokenStream {
let split_name: Vec<_> = self.name
.split(':')
.filter(|p| !p.is_empty())
- .map(|name| Term::new(name, Span::call_site()))
+ .map(|name| Ident::new(name, Span::call_site()))
.collect();
// No arguments
@@ -243,7 +242,7 @@ impl ObjCMethod {
let arg = arg.to_string();
let name_and_sig: Vec<&str> = arg.split(' ').collect();
let name = name_and_sig[0];
- args_without_types.push(Term::new(name, Span::call_site()))
+ args_without_types.push(Ident::new(name, Span::call_site()))
};
let args = split_name
diff --git a/src/lib.rs b/src/lib.rs
index ffe4e80d..a0202d18 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1675,7 +1675,7 @@ fn ensure_libclang_is_loaded() {
#[derive(Debug)]
pub struct Bindings {
options: BindgenOptions,
- module: quote::Tokens,
+ module: proc_macro2::TokenStream,
}
impl Bindings {
@@ -1863,7 +1863,7 @@ impl Bindings {
None => {
let path = which::which("rustfmt")
.map_err(|e| {
- io::Error::new(io::ErrorKind::Other, e.to_owned())
+ io::Error::new(io::ErrorKind::Other, format!("{}", e))
})?;
Cow::Owned(path)
diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs
index 43422ac5..df52a6d5 100644
--- a/tests/expectations/tests/accessors.rs
+++ b/tests/expectations/tests/accessors.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs
index 6657a950..d59ed05c 100644
--- a/tests/expectations/tests/annotation_hide.rs
+++ b/tests/expectations/tests/annotation_hide.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen opaque></div>
#[repr(C)]
diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs
index 6e6193c9..65442b94 100644
--- a/tests/expectations/tests/array-of-zero-sized-types.rs
+++ b/tests/expectations/tests/array-of-zero-sized-types.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// This should get an `_address` byte.
#[repr(C)]
diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs
index 905c7268..9cb1f152 100644
--- a/tests/expectations/tests/bitfield-32bit-overflow.rs
+++ b/tests/expectations/tests/bitfield-32bit-overflow.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs
index 1a0dbdb4..408c2a0e 100644
--- a/tests/expectations/tests/bitfield-large.rs
+++ b/tests/expectations/tests/bitfield-large.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs
index 8dda4538..46c4744e 100644
--- a/tests/expectations/tests/bitfield-method-same-name.rs
+++ b/tests/expectations/tests/bitfield-method-same-name.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs
index 0600052b..c7758c5a 100644
--- a/tests/expectations/tests/bitfield_align.rs
+++ b/tests/expectations/tests/bitfield_align.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs
index 7f5f689d..39ab0eef 100644
--- a/tests/expectations/tests/bitfield_align_2.rs
+++ b/tests/expectations/tests/bitfield_align_2.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs
index d778dd9b..0089d2c7 100644
--- a/tests/expectations/tests/bitfield_method_mangling.rs
+++ b/tests/expectations/tests/bitfield_method_mangling.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/blacklist-and-impl-debug.rs b/tests/expectations/tests/blacklist-and-impl-debug.rs
index 140342be..69f28a56 100644
--- a/tests/expectations/tests/blacklist-and-impl-debug.rs
+++ b/tests/expectations/tests/blacklist-and-impl-debug.rs
@@ -1,11 +1,14 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
pub struct BlacklistMe(u8);
-
/// Because this type contains a blacklisted type, it should not derive Debug.
#[repr(C)]
pub struct ShouldManuallyImplDebug {
diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs
index 5882328d..d1f6a5c0 100644
--- a/tests/expectations/tests/class_use_as.rs
+++ b/tests/expectations/tests/class_use_as.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen="true" replaces="whatever"></div>
#[repr(C)]
diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs
index 97afeefa..2e44746d 100644
--- a/tests/expectations/tests/comment-indent.rs
+++ b/tests/expectations/tests/comment-indent.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
@@ -109,7 +114,6 @@ pub mod root {
concat!("Alignment of ", stringify!(InInlineNS))
);
}
-
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Bazz {
diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs
index 16139a06..9036b12f 100644
--- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs
+++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// This should get an `_address` byte.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs
index c23b0264..70ee2973 100644
--- a/tests/expectations/tests/derive-bitfield-method-same-name.rs
+++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
@@ -100,7 +89,6 @@ where
}
}
}
-
/// Because this struct have array larger than 32 items
/// and --with-derive-partialeq --impl-partialeq --impl-debug is provided,
/// this struct should manually implement `Debug` and `PartialEq`.
diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs
index fda94f99..62042ffc 100644
--- a/tests/expectations/tests/derive-clone.rs
+++ b/tests/expectations/tests/derive-clone.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// This struct should derive `Clone`.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs
index c71eb92f..c2fafe8f 100644
--- a/tests/expectations/tests/derive-clone_1_0.rs
+++ b/tests/expectations/tests/derive-clone_1_0.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct
/// should impl `Clone` "manually".
diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs
index 59a01dbf..613e00f3 100644
--- a/tests/expectations/tests/derive-debug-bitfield-core.rs
+++ b/tests/expectations/tests/derive-debug-bitfield-core.rs
@@ -18,7 +18,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -27,38 +26,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -66,15 +56,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -85,16 +72,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs
index ccd7155d..88a41d78 100644
--- a/tests/expectations/tests/derive-debug-bitfield.rs
+++ b/tests/expectations/tests/derive-debug-bitfield.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/derive-default-and-blacklist.rs b/tests/expectations/tests/derive-default-and-blacklist.rs
index 7b1b1afc..1520aa3c 100644
--- a/tests/expectations/tests/derive-default-and-blacklist.rs
+++ b/tests/expectations/tests/derive-default-and-blacklist.rs
@@ -1,11 +1,14 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
pub struct BlacklistMe(u8);
-
/// Because this type contains a blacklisted type, it should not derive
/// Default. Instead, we should emit a `mem::zeroed` implementation.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-hash-and-blacklist.rs b/tests/expectations/tests/derive-hash-and-blacklist.rs
index ef12b9a8..92e918ca 100644
--- a/tests/expectations/tests/derive-hash-and-blacklist.rs
+++ b/tests/expectations/tests/derive-hash-and-blacklist.rs
@@ -1,11 +1,14 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
pub struct BlacklistMe(u8);
-
/// Because this type contains a blacklisted type, it should not derive Hash.
#[repr(C)]
pub struct ShouldNotDeriveHash {
diff --git a/tests/expectations/tests/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blacklisting.rs
index fa35d6ca..f64db062 100644
--- a/tests/expectations/tests/derive-hash-blacklisting.rs
+++ b/tests/expectations/tests/derive-hash-blacklisting.rs
@@ -1,7 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)]
@@ -10,7 +14,6 @@ pub struct Blacklisted<T> {
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
-
/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type,
/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
index 11c86de4..c3159532 100644
--- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
#[repr(C)]
diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs
index 12ac57aa..9ff64fde 100644
--- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
#[repr(C)]
diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs
index c69bcd7c..c0b14b02 100644
--- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq
#[repr(C)]
diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs
index 853d77af..b4040802 100644
--- a/tests/expectations/tests/derive-hash-template-def-float.rs
+++ b/tests/expectations/tests/derive-hash-template-def-float.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// Template definition containing a float, which cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs
index abb98f05..ee9b3f4c 100644
--- a/tests/expectations/tests/derive-hash-template-inst-float.rs
+++ b/tests/expectations/tests/derive-hash-template-inst-float.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// Template definition that doesn't contain float can derive Hash/PartialOrd/Ord/PartialEq/Eq
#[repr(C)]
diff --git a/tests/expectations/tests/derive-partialeq-and-blacklist.rs b/tests/expectations/tests/derive-partialeq-and-blacklist.rs
index 1c51c3a3..01fdc079 100644
--- a/tests/expectations/tests/derive-partialeq-and-blacklist.rs
+++ b/tests/expectations/tests/derive-partialeq-and-blacklist.rs
@@ -1,11 +1,14 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
pub struct BlacklistMe(u8);
-
/// Because this type contains a blacklisted type, it should not derive
/// PartialEq.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs
index c1cb18f7..f4d91662 100644
--- a/tests/expectations/tests/derive-partialeq-bitfield.rs
+++ b/tests/expectations/tests/derive-partialeq-bitfield.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
@@ -136,7 +125,8 @@ impl Default for C {
}
impl ::std::cmp::PartialEq for C {
fn eq(&self, other: &C) -> bool {
- self.a() == other.a() && self.b() == other.b()
+ self.a() == other.a()
+ && self.b() == other.b()
&& &self.large_array[..] == &other.large_array[..]
}
}
diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs
index 68344591..a271f410 100644
--- a/tests/expectations/tests/derive-partialeq-union.rs
+++ b/tests/expectations/tests/derive-partialeq-union.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// Deriving PartialEq for rust unions is not supported.
#[repr(C)]
diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs
index 57c415b4..41a42dd7 100644
--- a/tests/expectations/tests/derive-partialeq-union_1_0.rs
+++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
diff --git a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs
index 1b51a30f..1cdd1e09 100644
--- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs
+++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs
index cf576634..5a7aa86f 100644
--- a/tests/expectations/tests/doggo-or-null.rs
+++ b/tests/expectations/tests/doggo-or-null.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq)]
diff --git a/tests/expectations/tests/enum-variant-replaces.rs b/tests/expectations/tests/enum-variant-replaces.rs
index aabcad75..d710e100 100644
--- a/tests/expectations/tests/enum-variant-replaces.rs
+++ b/tests/expectations/tests/enum-variant-replaces.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen replaces="PASS"></div>
///
diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs
index cf8b283c..19200ac1 100644
--- a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs
+++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
pub struct BaseWithVtable__bindgen_vtable(::std::os::raw::c_void);
diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs
index 957360b7..cd0c7217 100644
--- a/tests/expectations/tests/issue-1034.rs
+++ b/tests/expectations/tests/issue-1034.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs
index 14eb4d5f..7a4b77fb 100644
--- a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs
+++ b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs
index 136f9e0c..8913db36 100644
--- a/tests/expectations/tests/issue-537.rs
+++ b/tests/expectations/tests/issue-537.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// This should not be opaque; we can see the attributes and can pack the
/// struct.
diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
index 0b0eb9a2..ddd85455 100644
--- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
+++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// We emit a `[u8; 63usize]` padding field for this struct, which cannot derive
/// Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn't end
diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs
index 7697660d..ce006656 100644
--- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs
+++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/issue-816.rs b/tests/expectations/tests/issue-816.rs
index b1a03081..d7be76ce 100644
--- a/tests/expectations/tests/issue-816.rs
+++ b/tests/expectations/tests/issue-816.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/issue-848-replacement-system-include.rs b/tests/expectations/tests/issue-848-replacement-system-include.rs
index 16fab93a..6e20983f 100644
--- a/tests/expectations/tests/issue-848-replacement-system-include.rs
+++ b/tests/expectations/tests/issue-848-replacement-system-include.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// This is intended to replace another type, but won't if we treat this include
/// as a system include, because clang doesn't parse comments there.
diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs
index 8143921d..5ca34ebb 100644
--- a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs
+++ b/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs
@@ -1,11 +1,14 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
pub struct BlacklistMe(u8);
-
/// Because this type contains a blacklisted type, it should not derive Copy.
#[repr(C)]
pub struct ShouldNotBeCopy {
diff --git a/tests/expectations/tests/issue_315.rs b/tests/expectations/tests/issue_315.rs
index d6660523..1eb30119 100644
--- a/tests/expectations/tests/issue_315.rs
+++ b/tests/expectations/tests/issue_315.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen replaces="c"></div>
pub type c<a> = a;
diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs
index 6a03de65..00b4301c 100644
--- a/tests/expectations/tests/jsval_layout_opaque.rs
+++ b/tests/expectations/tests/jsval_layout_opaque.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs
index e006ee42..7bd58819 100644
--- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs
+++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs
index a5fd1f69..a1350b14 100644
--- a/tests/expectations/tests/layout_align.rs
+++ b/tests/expectations/tests/layout_align.rs
@@ -16,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -25,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -64,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -83,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs
index d583e641..e8b72843 100644
--- a/tests/expectations/tests/layout_cmdline_token.rs
+++ b/tests/expectations/tests/layout_cmdline_token.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// Stores a pointer to the ops struct, and the offset: the place to
/// write the parsed result in the destination structure.
diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs
index 68aef5c6..5582c7de 100644
--- a/tests/expectations/tests/layout_eth_conf.rs
+++ b/tests/expectations/tests/layout_eth_conf.rs
@@ -16,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -25,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -64,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -83,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs
index 381ec8ac..b8c20f3d 100644
--- a/tests/expectations/tests/layout_eth_conf_1_0.rs
+++ b/tests/expectations/tests/layout_eth_conf_1_0.rs
@@ -16,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -25,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -64,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -83,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs
index 79b6d687..83dfb946 100644
--- a/tests/expectations/tests/layout_mbuf.rs
+++ b/tests/expectations/tests/layout_mbuf.rs
@@ -16,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -25,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -64,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -83,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs
index 71becc5f..a1ec285e 100644
--- a/tests/expectations/tests/layout_mbuf_1_0.rs
+++ b/tests/expectations/tests/layout_mbuf_1_0.rs
@@ -16,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -25,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -64,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -83,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs
index a09323a8..89e37fe8 100644
--- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs
+++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs
index 6272d773..f5e724d0 100644
--- a/tests/expectations/tests/no-derive-debug.rs
+++ b/tests/expectations/tests/no-derive-debug.rs
@@ -1,7 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Default)]
@@ -9,7 +13,6 @@ pub struct foo {
bar: ::std::os::raw::c_int,
}
-
/// bar should compile. It will normally derive debug, but our blacklist of foo
/// and replacement for another type that doesn't implement it would prevent it
/// from building if --no-derive-debug didn't work.
diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs
index da5e1001..cbf46c74 100644
--- a/tests/expectations/tests/no-derive-default.rs
+++ b/tests/expectations/tests/no-derive-default.rs
@@ -1,7 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug)]
@@ -9,7 +13,6 @@ pub struct foo {
bar: ::std::os::raw::c_int,
}
-
/// bar should compile. It will normally derive default, but our blacklist of foo
/// and replacement for another type that doesn't implement it would prevent it
/// from building if --no-derive-default didn't work.
diff --git a/tests/expectations/tests/no_copy.rs b/tests/expectations/tests/no_copy.rs
index 45249668..a61b457e 100644
--- a/tests/expectations/tests/no_copy.rs
+++ b/tests/expectations/tests/no_copy.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen nocopy></div>
#[repr(C)]
diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs
index 13713ed2..9d925217 100644
--- a/tests/expectations/tests/only_bitfields.rs
+++ b/tests/expectations/tests/only_bitfields.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs
index 99e507b8..b5afc667 100644
--- a/tests/expectations/tests/opaque-template-inst-member-2.rs
+++ b/tests/expectations/tests/opaque-template-inst-member-2.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// This is like `opaque-template-inst-member.hpp` except exercising the cases
/// where we are OK to derive Debug/Hash/PartialEq.
diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs
index 66531232..87e98daf 100644
--- a/tests/expectations/tests/opaque-template-inst-member.rs
+++ b/tests/expectations/tests/opaque-template-inst-member.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs
index 59848581..590c5fdc 100644
--- a/tests/expectations/tests/opaque_in_struct.rs
+++ b/tests/expectations/tests/opaque_in_struct.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen opaque>
#[repr(C)]
diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs
index 736655a4..c44a2440 100644
--- a/tests/expectations/tests/opaque_pointer.rs
+++ b/tests/expectations/tests/opaque_pointer.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen opaque></div>
#[repr(C)]
diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs
index 96df276c..75b79f20 100644
--- a/tests/expectations/tests/opaque_typedef.rs
+++ b/tests/expectations/tests/opaque_typedef.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs
index 52da1ae4..5088d9c9 100644
--- a/tests/expectations/tests/private.rs
+++ b/tests/expectations/tests/private.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs
index 38f0cc22..8fc38cd7 100644
--- a/tests/expectations/tests/reparented_replacement.rs
+++ b/tests/expectations/tests/reparented_replacement.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
diff --git a/tests/expectations/tests/replace_template_alias.rs b/tests/expectations/tests/replace_template_alias.rs
index 3ddde177..853ec092 100644
--- a/tests/expectations/tests/replace_template_alias.rs
+++ b/tests/expectations/tests/replace_template_alias.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// But the replacement type does use T!
///
diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs
index c5184b77..d8223031 100644
--- a/tests/expectations/tests/replace_use.rs
+++ b/tests/expectations/tests/replace_use.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// <div rustbindgen replaces="nsTArray"></div>
#[repr(C)]
diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs
index 9d49052e..dae55a13 100644
--- a/tests/expectations/tests/replaces_double.rs
+++ b/tests/expectations/tests/replaces_double.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs
index 7abd1087..31459452 100644
--- a/tests/expectations/tests/struct_with_bitfields.rs
+++ b/tests/expectations/tests/struct_with_bitfields.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs
index 6083265c..c0152972 100644
--- a/tests/expectations/tests/template.rs
+++ b/tests/expectations/tests/template.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Debug, Hash, PartialEq, Eq)]
diff --git a/tests/expectations/tests/templatized-bitfield.rs b/tests/expectations/tests/templatized-bitfield.rs
index 68ab6716..15785116 100644
--- a/tests/expectations/tests/templatized-bitfield.rs
+++ b/tests/expectations/tests/templatized-bitfield.rs
@@ -1,9 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
/// We don't get a layout for this bitfield, since we don't know what `T` will
/// be, so we cannot allocate bitfield units. The best thing we can do is make
diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs
index 0f884bfc..d6f52ef5 100644
--- a/tests/expectations/tests/union_bitfield.rs
+++ b/tests/expectations/tests/union_bitfield.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/tests/expectations/tests/union_bitfield_1_0.rs
index a86cee18..abc7c4b0 100644
--- a/tests/expectations/tests/union_bitfield_1_0.rs
+++ b/tests/expectations/tests/union_bitfield_1_0.rs
@@ -16,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -25,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -64,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -83,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs
index f5986246..e41fc973 100644
--- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs
+++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs
index 9a976071..83ee80eb 100644
--- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs
+++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs
index 5bedcadd..32220edb 100644
--- a/tests/expectations/tests/weird_bitfields.rs
+++ b/tests/expectations/tests/weird_bitfields.rs
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -11,7 +16,6 @@ where
storage: Storage,
align: [Align; 0],
}
-
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
where
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -20,38 +24,29 @@ where
pub fn new(storage: Storage) -> Self {
Self { storage, align: [] }
}
-
#[inline]
pub fn get_bit(&self, index: usize) -> bool {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = self.storage.as_ref()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
-
byte & mask == mask
}
-
#[inline]
pub fn set_bit(&mut self, index: usize, val: bool) {
debug_assert!(index / 8 < self.storage.as_ref().len());
-
let byte_index = index / 8;
let byte = &mut self.storage.as_mut()[byte_index];
-
let bit_index = if cfg!(target_endian = "big") {
7 - (index % 8)
} else {
index % 8
};
-
let mask = 1 << bit_index;
if val {
*byte |= mask;
@@ -59,15 +54,12 @@ where
*byte &= !mask;
}
}
-
#[inline]
pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
let mut val = 0;
-
for i in 0..(bit_width as usize) {
if self.get_bit(i + bit_offset) {
let index = if cfg!(target_endian = "big") {
@@ -78,16 +70,13 @@ where
val |= 1 << index;
}
}
-
val
}
-
#[inline]
pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
debug_assert!(bit_width <= 64);
debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
-
for i in 0..(bit_width as usize) {
let mask = 1 << i;
let val_bit_is_set = val & mask == mask;
diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs
index 11ad0fe6..4464bb4b 100644
--- a/tests/expectations/tests/zero-sized-array.rs
+++ b/tests/expectations/tests/zero-sized-array.rs
@@ -1,8 +1,11 @@
/* automatically generated by rust-bindgen */
-
-#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
-
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
#[repr(C)]
#[derive(Default)]
diff --git a/tests/rustfmt.toml b/tests/rustfmt.toml
index 80a6663b..e8bb3d9a 100644
--- a/tests/rustfmt.toml
+++ b/tests/rustfmt.toml
@@ -1 +1 @@
-# Intentionally left blank.
+normalize_doc_attributes = true