From 5a730ab4dc4bec693c4655fc26ebf1b4d1bc2016 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Tue, 29 May 2018 12:33:02 +0200 Subject: [PATCH] WIP: Quote 0.6 --- Cargo.lock | 14 +- Cargo.toml | 4 +- src/codegen/helpers.rs | 59 ++-- src/codegen/impl_debug.rs | 16 +- src/codegen/impl_partialeq.rs | 9 +- src/codegen/mod.rs | 198 ++++++------ src/codegen/struct_layout.rs | 11 +- src/ir/comment.rs | 12 +- src/ir/context.rs | 10 +- src/ir/function.rs | 4 +- src/ir/objc.rs | 9 +- src/lib.rs | 2 +- tests/expectations/tests/accessors.rs | 24 +- tests/expectations/tests/annotation_hide.rs | 5 +- .../tests/array-of-zero-sized-types.rs | 8 +- .../tests/bitfield-32bit-overflow.rs | 15 - tests/expectations/tests/bitfield-large.rs | 17 - .../tests/bitfield-method-same-name.rs | 17 - tests/expectations/tests/bitfield_align.rs | 15 - tests/expectations/tests/bitfield_align_2.rs | 15 - .../tests/bitfield_method_mangling.rs | 17 - .../tests/blacklist-and-impl-debug.rs | 4 +- tests/expectations/tests/class_use_as.rs | 5 +- tests/expectations/tests/comment-indent.rs | 25 +- tests/expectations/tests/constify-enum.rs | 2 +- .../tests/contains-vs-inherits-zero-sized.rs | 11 +- .../tests/convert-cpp-comment-to-rust.rs | 10 +- .../tests/derive-bitfield-method-same-name.rs | 20 +- tests/expectations/tests/derive-clone.rs | 5 +- tests/expectations/tests/derive-clone_1_0.rs | 6 +- .../tests/derive-debug-bitfield.rs | 17 - .../tests/derive-default-and-blacklist.rs | 5 +- .../tests/derive-hash-and-blacklist.rs | 4 +- .../tests/derive-hash-blacklisting.rs | 7 +- ...rive-hash-struct-with-anon-struct-float.rs | 5 +- .../derive-hash-struct-with-float-array.rs | 5 +- .../tests/derive-hash-struct-with-pointer.rs | 2 +- .../tests/derive-hash-template-def-float.rs | 5 +- .../tests/derive-hash-template-inst-float.rs | 9 +- .../tests/derive-partialeq-and-blacklist.rs | 5 +- .../tests/derive-partialeq-bitfield.rs | 17 - .../tests/derive-partialeq-union.rs | 5 +- .../tests/derive-partialeq-union_1_0.rs | 4 +- .../tests/divide-by-zero-in-struct-layout.rs | 17 - tests/expectations/tests/doggo-or-null.rs | 9 +- tests/expectations/tests/enum-doc-bitfield.rs | 17 +- tests/expectations/tests/enum-doc-mod.rs | 17 +- tests/expectations/tests/enum-doc-rusty.rs | 17 +- tests/expectations/tests/enum-doc.rs | 17 +- .../tests/enum-variant-replaces.rs | 10 +- ...from-template-instantiation-with-vtable.rs | 14 +- tests/expectations/tests/issue-1034.rs | 17 - .../issue-1076-unnamed-bitfield-alignment.rs | 17 - tests/expectations/tests/issue-537.rs | 17 +- .../issue-648-derive-debug-with-padding.rs | 13 +- .../tests/issue-739-pointer-wide-bitfield.rs | 15 - tests/expectations/tests/issue-816.rs | 15 - .../issue-848-replacement-system-include.rs | 10 +- .../issue-944-derive-copy-and-blacklisting.rs | 4 +- tests/expectations/tests/issue_315.rs | 5 +- .../expectations/tests/jsval_layout_opaque.rs | 53 ++-- .../tests/jsval_layout_opaque_1_0.rs | 53 ++-- tests/expectations/tests/layout_align.rs | 29 +- tests/expectations/tests/layout_arp.rs | 24 +- tests/expectations/tests/layout_array.rs | 51 ++- .../tests/layout_array_too_long.rs | 41 ++- .../tests/layout_cmdline_token.rs | 29 +- tests/expectations/tests/layout_eth_conf.rs | 298 +++++++----------- .../expectations/tests/layout_eth_conf_1_0.rs | 298 +++++++----------- tests/expectations/tests/layout_kni_mbuf.rs | 10 +- .../tests/layout_large_align_field.rs | 79 +++-- tests/expectations/tests/layout_mbuf.rs | 95 ++---- tests/expectations/tests/layout_mbuf_1_0.rs | 95 ++---- .../type_alias_template_specialized.rs | 4 +- tests/expectations/tests/no-derive-debug.rs | 6 +- tests/expectations/tests/no-derive-default.rs | 6 +- tests/expectations/tests/no_copy.rs | 5 +- tests/expectations/tests/only_bitfields.rs | 17 - .../tests/opaque-template-inst-member-2.rs | 10 +- .../tests/opaque-template-inst-member.rs | 8 +- tests/expectations/tests/opaque_in_struct.rs | 5 +- tests/expectations/tests/opaque_pointer.rs | 7 +- tests/expectations/tests/opaque_typedef.rs | 4 +- tests/expectations/tests/private.rs | 10 +- .../tests/reparented_replacement.rs | 4 +- .../tests/replace_template_alias.rs | 7 +- tests/expectations/tests/replace_use.rs | 5 +- tests/expectations/tests/replaces_double.rs | 4 +- .../tests/struct_with_bitfields.rs | 15 - tests/expectations/tests/template.rs | 14 +- .../tests/templatized-bitfield.rs | 7 +- tests/expectations/tests/union_bitfield.rs | 17 - .../expectations/tests/union_bitfield_1_0.rs | 17 - .../tests/union_with_anon_struct_bitfield.rs | 17 - .../union_with_anon_struct_bitfield_1_0.rs | 17 - tests/expectations/tests/weird_bitfields.rs | 15 - tests/expectations/tests/zero-sized-array.rs | 13 +- 97 files changed, 736 insertions(+), 1543 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35eceb2a42..fe37bee148 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,8 +34,8 @@ dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (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.2 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.0 (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.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -175,7 +175,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.3.2" +version = "0.4.4" 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)", @@ -188,10 +188,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "quote" -version = "0.5.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -370,9 +370,9 @@ dependencies = [ "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -"checksum proc-macro2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "681c2c8e039ff358cb926dbc5151d561cbd0249089986ace39dfe8e405bb7511" +"checksum proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1fa93823f53cfd0f5ac117b189aed6cfdfb2cfc0a9d82e956dd7927595ed7d46" "checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4" -"checksum quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0ff51282f28dc1b53fd154298feaa2e77c5ea0dba68e1fd8b03b72fbe13d2a" +"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035" "checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3" "checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" diff --git a/Cargo.toml b/Cargo.toml index 6006216442..3563056189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,12 +50,12 @@ clap = "2" clang-sys = { version = "0.22.0", 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" # 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/src/codegen/helpers.rs b/src/codegen/helpers.rs index f1007c51e6..b14afcf25d 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -2,53 +2,45 @@ use ir::context::BindgenContext; use ir::layout::Layout; -use quote; use std::mem; -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 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 { + quote! {#[doc=#comment]} } - 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); @@ -60,7 +52,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(layout: Layout) -> quote::Tokens { +pub fn blob(layout: Layout) -> proc_macro2::TokenStream { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are @@ -75,7 +67,7 @@ pub fn blob(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().unwrap_or(layout.size); @@ -91,7 +83,7 @@ pub fn blob(layout: Layout) -> quote::Tokens { } /// Integer type of the same size as the given `Layout`. -pub fn integer_type(layout: Layout) -> Option { +pub fn integer_type(layout: Layout) -> Option { // This guard can be weakened when Rust implements u128. if layout.size > mem::size_of::() { None @@ -101,7 +93,7 @@ pub fn integer_type(layout: Layout) -> Option { } /// 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 { @@ -127,10 +119,9 @@ pub mod ast_ty { use ir::context::BindgenContext; use ir::function::FunctionSig; 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) => { @@ -148,7 +139,7 @@ pub mod ast_ty { pub fn float_kind_rust_type( ctx: &BindgenContext, fk: FloatKind, - ) -> quote::Tokens { + ) -> proc_macro2::TokenStream { // TODO: we probably should just take the type layout into // account? // @@ -167,25 +158,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! { @@ -196,7 +187,7 @@ pub mod ast_ty { pub fn float_expr( ctx: &BindgenContext, f: f64, - ) -> Result { + ) -> Result { if f.is_finite() { let val = proc_macro2::Literal::f64_unsuffixed(f); @@ -230,7 +221,7 @@ pub mod ast_ty { pub fn arguments_from_signature( signature: &FunctionSig, ctx: &BindgenContext, - ) -> Vec { + ) -> Vec { let mut unnamed_arguments = 0; signature .argument_types() diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs index ab934ed6cc..cef15a0f36 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![]; @@ -61,7 +61,7 @@ pub trait ImplDebug<'a> { &self, ctx: &BindgenContext, extra: Self::Extra, - ) -> Option<(String, Vec)>; + ) -> Option<(String, Vec)>; } impl<'a> ImplDebug<'a> for FieldData { @@ -71,7 +71,7 @@ impl<'a> ImplDebug<'a> for FieldData { &self, ctx: &BindgenContext, _: Self::Extra, - ) -> Option<(String, Vec)> { + ) -> Option<(String, Vec)> { if let Some(name) = self.name() { ctx.resolve_item(self.ty()).impl_debug(ctx, name) } else { @@ -87,7 +87,7 @@ impl<'a> ImplDebug<'a> for BitfieldUnit { &self, ctx: &BindgenContext, _: Self::Extra, - ) -> Option<(String, Vec)> { + ) -> Option<(String, Vec)> { let mut format_string = String::new(); let mut tokens = vec![]; for (i, bitfield) in self.bitfields().iter().enumerate() { @@ -116,7 +116,7 @@ impl<'a> ImplDebug<'a> for Item { &self, ctx: &BindgenContext, name: &str, - ) -> Option<(String, Vec)> { + ) -> Option<(String, Vec)> { let name_ident = ctx.rust_ident(name); // We don't know if blacklisted items `impl Debug` or not, so we can't @@ -134,8 +134,8 @@ impl<'a> ImplDebug<'a> for Item { fn debug_print( name: &str, - name_ident: quote::Tokens, - ) -> Option<(String, Vec)> { + name_ident: proc_macro2::TokenStream, + ) -> Option<(String, Vec)> { Some(( format!("{}: {{:?}}", name), vec![quote! { diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs index a05c65e7ff..6a0294039b 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: "e::Tokens, -) -> Option { + ty_for_impl: &proc_macro2::TokenStream, +) -> Option { 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 026e9475d0..8309bd6e18 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 { +fn top_level_path(ctx: &BindgenContext, item: &Item) -> Vec { 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 { 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, + items: Vec, /// A monotonic counter used to add stable unique id's to stuff that doesn't /// need to be referenced by anything. @@ -204,7 +205,7 @@ impl<'a> CodegenResult<'a> { self.vars_seen.insert(name.into()); } - fn inner(&mut self, cb: F) -> Vec + fn inner(&mut self, cb: F) -> Vec where F: FnOnce(&mut Self), { @@ -222,7 +223,7 @@ impl<'a> CodegenResult<'a> { } impl<'a> ops::Deref for CodegenResult<'a> { - type Target = Vec; + type Target = Vec; fn deref(&self) -> &Self::Target { &self.items @@ -238,11 +239,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 { @@ -251,7 +252,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( @@ -261,7 +262,7 @@ trait AppendImplicitTemplateParams { ); } -impl AppendImplicitTemplateParams for quote::Tokens { +impl AppendImplicitTemplateParams for proc_macro2::TokenStream { fn append_implicit_template_params( &mut self, ctx: &BindgenContext, @@ -428,10 +429,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()); } } @@ -705,7 +703,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 ; }); @@ -817,7 +815,7 @@ impl<'a> TryToRustTy for Vtable<'a> { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { let name = ctx.rust_ident(self.canonical_name(ctx)); Ok(quote! { #name @@ -912,8 +910,8 @@ trait FieldCodegen<'a> { methods: &mut M, extra: Self::Extra, ) where - F: Extend, - M: Extend; + F: Extend, + M: Extend; } impl<'a> FieldCodegen<'a> for Field { @@ -932,8 +930,8 @@ impl<'a> FieldCodegen<'a> for Field { methods: &mut M, _: (), ) where - F: Extend, - M: Extend, + F: Extend, + M: Extend, { match *self { Field::DataMember(ref data) => { @@ -984,8 +982,8 @@ impl<'a> FieldCodegen<'a> for FieldData { methods: &mut M, _: (), ) where - F: Extend, - M: Extend, + F: Extend, + M: Extend, { // Bitfields are handled by `FieldCodegen` implementations for // `BitfieldUnit` and `Bitfield`. @@ -1119,8 +1117,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 } @@ -1138,9 +1136,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!", @@ -1184,8 +1182,8 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { methods: &mut M, _: (), ) where - F: Extend, - M: Extend, + F: Extend, + M: Extend, { result.saw_bitfield_unit(); @@ -1282,7 +1280,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 } @@ -1291,7 +1289,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 } @@ -1313,13 +1311,13 @@ impl<'a> FieldCodegen<'a> for Bitfield { methods: &mut M, (unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool), ) where - F: Extend, - M: Extend, + F: Extend, + M: Extend, { 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(); @@ -1745,7 +1743,7 @@ impl CodeGenerator for CompInfo { if self.found_unknown_attr() { warn!( "Type {} has an unkown attribute that may affect layout", - canonical_ident.as_str() + canonical_ident ); } @@ -1759,7 +1757,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! { @@ -1821,7 +1819,7 @@ impl CodeGenerator for CompInfo { }) }) }) - .collect::>(); + .collect::>(); asserts }; @@ -1959,7 +1957,7 @@ trait MethodCodegen { fn codegen_method<'a>( &self, ctx: &BindgenContext, - methods: &mut Vec, + methods: &mut Vec, method_names: &mut HashMap, result: &mut CodegenResult<'a>, parent: &CompInfo, @@ -1970,7 +1968,7 @@ impl MethodCodegen for Method { fn codegen_method<'a>( &self, ctx: &BindgenContext, - methods: &mut Vec, + methods: &mut Vec, method_names: &mut HashMap, result: &mut CodegenResult<'a>, _parent: &CompInfo, @@ -2170,24 +2168,24 @@ impl std::str::FromStr for EnumVariation { enum EnumBuilder<'a> { Rust { codegen_depth: usize, - attrs: Vec, - ident: Term, - tokens: quote::Tokens, + attrs: Vec, + 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, + variants: Vec, codegen_depth: usize, }, ModuleConsts { codegen_depth: usize, module_name: &'a str, - module_items: Vec, + module_items: Vec, }, } @@ -2206,12 +2204,12 @@ impl<'a> EnumBuilder<'a> { /// the representation, and which variation it should be generated as. fn new( name: &'a str, - attrs: Vec, - repr: quote::Tokens, + attrs: Vec, + 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 => { @@ -2249,7 +2247,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; @@ -2270,7 +2268,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 { @@ -2372,9 +2370,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 { @@ -2549,23 +2547,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); @@ -2589,7 +2587,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); @@ -2649,7 +2647,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, @@ -2689,11 +2687,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() ) @@ -2703,7 +2701,7 @@ impl CodeGenerator for Enum { ctx, enum_ty, &ident, - mangled_name.as_str(), + &mangled_name, &variant_name, enum_rust_ty.clone(), result, @@ -2740,7 +2738,7 @@ trait TryToOpaque { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> error::Result { + ) -> error::Result { self.try_get_layout(ctx, extra).map(|layout| { helpers::blob(layout) }) @@ -2767,7 +2765,7 @@ trait ToOpaque: TryToOpaque { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> quote::Tokens { + ) -> proc_macro2::TokenStream { let layout = self.get_layout(ctx, extra); helpers::blob(layout) } @@ -2793,7 +2791,7 @@ trait TryToRustTy { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> error::Result; + ) -> error::Result; } /// Fallible conversion to a Rust type or an opaque blob with the correct size @@ -2808,7 +2806,7 @@ trait TryToRustTyOrOpaque: TryToRustTy + TryToOpaque { &self, ctx: &BindgenContext, extra: &::Extra, - ) -> error::Result; + ) -> error::Result; } impl TryToRustTyOrOpaque for T @@ -2822,7 +2820,7 @@ where &self, ctx: &BindgenContext, extra: &E, - ) -> error::Result { + ) -> error::Result { self.try_to_rust_ty(ctx, extra).or_else( |_| if let Ok(layout) = self.try_get_layout(ctx, extra) @@ -2859,7 +2857,7 @@ trait ToRustTyOrOpaque: TryToRustTy + ToOpaque { &self, ctx: &BindgenContext, extra: &::Extra, - ) -> quote::Tokens; + ) -> proc_macro2::TokenStream; } impl ToRustTyOrOpaque for T @@ -2872,7 +2870,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) }) @@ -2904,7 +2902,7 @@ where &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { ctx.resolve_item((*self).into()).try_to_rust_ty(ctx, &()) } } @@ -2928,7 +2926,7 @@ impl TryToRustTy for Item { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { self.kind().expect_type().try_to_rust_ty(ctx, self) } } @@ -2952,7 +2950,7 @@ impl TryToRustTy for Type { &self, ctx: &BindgenContext, item: &Item, - ) -> error::Result { + ) -> error::Result { use self::helpers::ast_ty::*; match *self.kind() { @@ -3038,7 +3036,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) => { @@ -3148,7 +3146,7 @@ impl TryToRustTy for TemplateInstantiation { &self, ctx: &BindgenContext, item: &Item, - ) -> error::Result { + ) -> error::Result { if self.is_opaque(ctx, item) { return Err(error::Error::InstantiationOfOpaqueType); } @@ -3160,7 +3158,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() { @@ -3212,7 +3210,7 @@ impl TryToRustTy for FunctionSig { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { // TODO: we might want to consider ignoring the reference return value. let ret = utils::fnsig_return_ty(ctx, &self); let arguments = utils::fnsig_arguments(ctx, &self); @@ -3221,7 +3219,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! { @@ -3343,7 +3341,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); @@ -3457,7 +3455,7 @@ impl CodeGenerator for ObjCInterface { } } -pub(crate) fn codegen(context: BindgenContext) -> (Vec, BindgenOptions) { +pub(crate) fn codegen(context: BindgenContext) -> (Vec, BindgenOptions) { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); @@ -3493,12 +3491,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) { - let bitfield_unit_type = Term::new(include_str!("./bitfield_unit.rs"), Span::call_site()); + pub fn prepend_bitfield_unit_type(result: &mut Vec) { + 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]; @@ -3508,7 +3506,7 @@ mod utils { pub fn prepend_objc_header( ctx: &BindgenContext, - result: &mut Vec, + result: &mut Vec, ) { let use_objc = if ctx.options().objc_extern_crate { quote! { @@ -3533,7 +3531,7 @@ mod utils { pub fn prepend_union_types( ctx: &BindgenContext, - result: &mut Vec, + result: &mut Vec, ) { let prefix = ctx.trait_prefix(); @@ -3632,7 +3630,7 @@ mod utils { pub fn prepend_incomplete_array_types( ctx: &BindgenContext, - result: &mut Vec, + result: &mut Vec, ) { let prefix = ctx.trait_prefix(); @@ -3705,7 +3703,7 @@ mod utils { } pub fn prepend_complex_type( - result: &mut Vec, + result: &mut Vec, ) { let complex_type = quote! { #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] @@ -3724,18 +3722,14 @@ mod utils { pub fn build_path( item: &Item, ctx: &BindgenContext, - ) -> error::Result { - use proc_macro2::{Term, Span}; - + ) -> error::Result { 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 @@ -3745,7 +3739,7 @@ mod utils { pub fn type_from_named( ctx: &BindgenContext, name: &str, - ) -> Option { + ) -> Option { // FIXME: We could use the inner item to check this is really a // primitive type but, who the heck overrides these anyway? Some(match name { @@ -3768,7 +3762,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! { } @@ -3783,7 +3777,7 @@ mod utils { pub fn fnsig_arguments( ctx: &BindgenContext, sig: &FunctionSig, - ) -> Vec { + ) -> Vec { use super::ToPtr; let mut unnamed_arguments = 0; diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 6de7e03069..f2007329b5 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, - ) -> Option { + ) -> Option { 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 { + pub fn pad_struct(&mut self, layout: Layout) -> Option { debug!( "pad_struct:\n\tself = {:#?}\n\tlayout = {:#?}", self, @@ -305,13 +304,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(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/comment.rs b/src/ir/comment.rs index 6a87c492af..4b163c7426 100644 --- a/src/ir/comment.rs +++ b/src/ir/comment.rs @@ -54,7 +54,7 @@ fn preprocess_single_lines(comment: &str, indent: usize) -> String { let indent = if is_first { "" } else { &*indent }; is_first = false; let maybe_space = if l.is_empty() { "" } else { " " }; - format!("{}///{}{}", indent, maybe_space, l) + format!("{}{}{}", indent, maybe_space, l) }) .collect(); lines.join("\n") @@ -79,7 +79,7 @@ fn preprocess_multi_line(comment: &str, indent: usize) -> String { let indent = if is_first { "" } else { &*indent }; is_first = false; let maybe_space = if line.is_empty() { "" } else { " " }; - format!("{}///{}{}", indent, maybe_space, line) + format!("{}{}{}", indent, maybe_space, line) }) .collect(); @@ -105,20 +105,20 @@ mod test { #[test] fn processes_single_lines_correctly() { - assert_eq!(preprocess("/// hello", 0), "/// hello"); - assert_eq!(preprocess("// hello", 0), "/// hello"); + assert_eq!(preprocess("/// hello", 0), " hello"); + assert_eq!(preprocess("// hello", 0), " hello"); } #[test] fn processes_multi_lines_correctly() { assert_eq!( preprocess("/** hello \n * world \n * foo \n */", 0), - "/// hello\n/// world\n/// foo" + " hello\n world\n foo" ); assert_eq!( preprocess("/**\nhello\n*world\n*foo\n*/", 0), - "/// hello\n/// world\n/// foo" + " hello\n world\n foo" ); } } diff --git a/src/ir/context.rs b/src/ir/context.rs index 86dcda568f..a8710505f7 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}; @@ -905,7 +905,7 @@ impl BindgenContext { } /// Returns a mangled name as a rust identifier. - pub fn rust_ident(&self, name: S) -> Term + pub fn rust_ident(&self, name: S) -> Ident where S: AsRef { @@ -913,11 +913,11 @@ impl BindgenContext { } /// Returns a mangled name as a rust identifier. - pub fn rust_ident_raw(&self, name: T) -> Term + pub fn rust_ident_raw(&self, name: T) -> Ident where T: AsRef { - Term::new(name.as_ref(), Span::call_site()) + Ident::new(name.as_ref(), Span::call_site()) } /// Iterate over all items that have been defined. @@ -2376,7 +2376,7 @@ impl BindgenContext { /// 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 5e8d2fc8d5..b6f8c700e5 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 46c0802e87..61c2235635 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 7dd39138ff..723de6f75b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1578,7 +1578,7 @@ fn ensure_libclang_is_loaded() { #[derive(Debug)] pub struct Bindings { options: BindgenOptions, - module: quote::Tokens, + module: proc_macro2::TokenStream, } impl Bindings { diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index 43422ac5b9..71bed1d8ab 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -1,18 +1,16 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct SomeAccessors { pub mNoAccessor: ::std::os::raw::c_int, - ///
+ #[doc = "
"] pub mBothAccessors: ::std::os::raw::c_int, - ///
+ #[doc = "
"] pub mUnsafeAccessors: ::std::os::raw::c_int, - ///
+ #[doc = "
"] pub mImmutableAccessor: ::std::os::raw::c_int, } #[test] @@ -92,7 +90,7 @@ impl SomeAccessors { &self.mImmutableAccessor } } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllAccessors { @@ -150,7 +148,7 @@ impl AllAccessors { &mut self.mAlsoBothAccessors } } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllUnsafeAccessors { @@ -212,16 +210,16 @@ impl AllUnsafeAccessors { &mut self.mAlsoBothAccessors } } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ContradictAccessors { pub mBothAccessors: ::std::os::raw::c_int, - ///
+ #[doc = "
"] pub mNoAccessors: ::std::os::raw::c_int, - ///
+ #[doc = "
"] pub mUnsafeAccessors: ::std::os::raw::c_int, - ///
+ #[doc = "
"] pub mImmutableAccessor: ::std::os::raw::c_int, } #[test] @@ -307,7 +305,7 @@ impl ContradictAccessors { &self.mImmutableAccessor } } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Replaced { @@ -346,7 +344,7 @@ impl Replaced { &mut self.mAccessor } } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Wrapper { diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index 6657a9502d..936ad6a090 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct D { diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index 6e6193c98e..d95da41493 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// This should get an `_address` byte. +#[doc = " This should get an `_address` byte."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Empty { @@ -24,8 +21,7 @@ fn bindgen_test_layout_Empty() { concat!("Alignment of ", stringify!(Empty)) ); } -/// This should not get an `_address` byte, since each `Empty` gets one, meaning -/// that this object is addressable. +#[doc = " This should not get an `_address` byte, since each `Empty` gets one, meaning\n that this object is addressable."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct HasArrayOfEmpty { diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs index 7270649e6b..bc476d9d65 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 7b93f1190b..d9ee670446 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 b8700605a4..8059a37276 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 9821aa6fdf..d7a309e8dd 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 5d63699d48..97cb5474a1 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 e557f92b2d..4ac5b80b91 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 a5528af155..1c2cc86986 100644 --- a/tests/expectations/tests/blacklist-and-impl-debug.rs +++ b/tests/expectations/tests/blacklist-and-impl-debug.rs @@ -1,12 +1,10 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " Because this type contains a blacklisted type, it should not derive Debug."] #[repr(C)] pub struct ShouldManuallyImplDebug { pub a: BlacklistMe, diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index 5882328d9b..bfe453ad82 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever { diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index 97afeefa95..69db7ca28f 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -6,17 +6,13 @@ pub mod root { #[allow(unused_imports)] use self::super::root; - /// This is a multi-line doc comment. - /// - /// This class is really really interesting, look! + #[doc = " This is a multi-line doc comment.\n \n This class is really really interesting, look!"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } - /// This nested class is also a multi-line doc comment. - /// - /// This class is not so interesting, but worth a bit of docs too! + #[doc = " This nested class is also a multi-line doc comment.\n \n This class is not so interesting, but worth a bit of docs too!"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar { @@ -51,18 +47,11 @@ pub mod root { pub mod test { #[allow(unused_imports)] use self::super::super::root; - /// I'm in a namespace, and thus I may be on a rust module, most of the time. - /// My documentation is pretty extensive, I guess. + #[doc = " I\'m in a namespace, and thus I may be on a rust module, most of the time.\n My documentation is pretty extensive, I guess."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { - /// This member is plain awesome, just amazing. - /// - /// It also has super-extensive docs, with even a nice ascii-art diagram. - /// - /// +------+ +-------+ - /// | foo | ----> | bar | - /// +------+ +-------+ + #[doc = " This member is plain awesome, just amazing.\n \n It also has super-extensive docs, with even a nice ascii-art diagram.\n \n +------+ +-------+\n | foo | ----> | bar |\n +------+ +-------+"] pub member: ::std::os::raw::c_int, } #[test] @@ -88,9 +77,7 @@ pub mod root { ) ); } - /// I'm in an inline namespace, and as such I shouldn't get generated inside - /// a rust module, except when the relevant option is specified. Also, this - /// comment shouldn't be misaligned. + #[doc = " I\'m in an inline namespace, and as such I shouldn\'t get generated inside\n a rust module, except when the relevant option is specified. Also, this\n comment shouldn\'t be misaligned."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InInlineNS { @@ -109,7 +96,7 @@ pub mod root { concat!("Alignment of ", stringify!(InInlineNS)) ); } - + #[doc = ""] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bazz { diff --git a/tests/expectations/tests/constify-enum.rs b/tests/expectations/tests/constify-enum.rs index 07279cf301..c4f188729f 100644 --- a/tests/expectations/tests/constify-enum.rs +++ b/tests/expectations/tests/constify-enum.rs @@ -13,6 +13,6 @@ pub enum nsCSSPropertyID { eCSSProperty_b = 1, eCSSPropertyAlias_aa = 2, eCSSPropertyAlias_bb = 3, - /// <
+ #[doc = " <
"] eCSSProperty_COUNT_unexistingVariantValue = 4, } diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 16139a0647..4a9468d8f2 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// This should get an `_address` byte. +#[doc = " This should get an `_address` byte."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Empty { @@ -24,8 +21,7 @@ fn bindgen_test_layout_Empty() { concat!("Alignment of ", stringify!(Empty)) ); } -/// This should not get an `_address` byte, so `sizeof(Inherits)` should be -/// `1`. +#[doc = " This should not get an `_address` byte, so `sizeof(Inherits)` should be\n `1`."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Inherits { @@ -54,8 +50,7 @@ fn bindgen_test_layout_Inherits() { ) ); } -/// This should not get an `_address` byte, but contains `Empty` which *does* get -/// one, so `sizeof(Contains)` should be `1 + 1`. +#[doc = " This should not get an `_address` byte, but contains `Empty` which *does* get\n one, so `sizeof(Contains)` should be `1 + 1`."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Contains { diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs index f9f8e200d1..0e41580c09 100644 --- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -1,19 +1,17 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - pub type mbedtls_mpi_uint = ::std::os::raw::c_uint; -/// \brief MPI structure +#[doc = " \\brief MPI structure"] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct mbedtls_mpi { - /// < integer sign + #[doc = " < integer sign"] pub s: ::std::os::raw::c_int, - /// < total # of limbs + #[doc = " < total # of limbs"] pub n: ::std::os::raw::c_ulong, - /// < pointer to limbs + #[doc = " < pointer to limbs"] pub p: *mut mbedtls_mpi_uint, } #[test] diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index f9d29afd13..2be114a9c4 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -81,10 +66,7 @@ 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`. +#[doc = " Because this struct have array larger than 32 items\n and --with-derive-partialeq --impl-partialeq --impl-debug is provided,\n this struct should manually implement `Debug` and `PartialEq`."] #[repr(C)] #[derive(Copy, Clone)] pub struct Foo { diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index fda94f9972..4968321173 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// This struct should derive `Clone`. +#[doc = " This struct should derive `Clone`."] #[repr(C)] #[derive(Copy, Clone)] pub struct ShouldDeriveClone { diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index c71eb92fa9..1e99e59f55 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -1,12 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct -/// should impl `Clone` "manually". +#[doc = " Since builtin `Clone` impls were introduced in Rust 1.21 this struct\n should impl `Clone` \"manually\"."] #[repr(C)] #[derive(Copy)] pub struct ShouldImplClone { diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 3743b8d968..e518866415 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 7b1b1afca8..35fbca538c 100644 --- a/tests/expectations/tests/derive-default-and-blacklist.rs +++ b/tests/expectations/tests/derive-default-and-blacklist.rs @@ -1,13 +1,10 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " Because this type contains a blacklisted type, it should not derive\n Default. Instead, we should emit a `mem::zeroed` implementation."] #[repr(C)] pub struct ShouldNotDeriveDefault { pub a: BlacklistMe, diff --git a/tests/expectations/tests/derive-hash-and-blacklist.rs b/tests/expectations/tests/derive-hash-and-blacklist.rs index ef12b9a8ab..30a3b606ff 100644 --- a/tests/expectations/tests/derive-hash-and-blacklist.rs +++ b/tests/expectations/tests/derive-hash-and-blacklist.rs @@ -1,12 +1,10 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " Because this type contains a blacklisted type, it should not derive Hash."] #[repr(C)] pub struct ShouldNotDeriveHash { pub a: BlacklistMe, diff --git a/tests/expectations/tests/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blacklisting.rs index fa35d6ca54..9de5fdf3dc 100644 --- a/tests/expectations/tests/derive-hash-blacklisting.rs +++ b/tests/expectations/tests/derive-hash-blacklisting.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] @@ -10,9 +9,7 @@ pub struct Blacklisted { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } - -/// 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. +#[doc = " This would derive(Hash, Eq, PartialEq) if it didn\'t contain a blacklisted type,\n causing us to conservatively avoid deriving hash/Eq/PartialEq for it."] #[repr(C)] pub struct WhitelistedOne { pub a: Blacklisted<::std::os::raw::c_int>, @@ -45,7 +42,7 @@ impl Default for WhitelistedOne { unsafe { ::std::mem::zeroed() } } } -/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type. +#[doc = " This can\'t derive(Hash/Eq) even if it didn\'t contain a blacklisted type."] #[repr(C)] pub struct WhitelistedTwo { pub b: Blacklisted, 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 11c86de473..e08008e7a4 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,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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 +#[doc = " A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { 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 12ac57aabc..d4c2426a59 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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 +#[doc = " A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index c69bcd7c4e..efe208817c 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -2,7 +2,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -/// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq +#[doc = " Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct ConstPtrMutObj { diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs index 853d77affe..32b8f65db9 100644 --- a/tests/expectations/tests/derive-hash-template-def-float.rs +++ b/tests/expectations/tests/derive-hash-template-def-float.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " Template definition containing a float, which cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd."] #[repr(C)] #[derive(Debug, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index abb98f0515..8b3668558f 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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 +#[doc = " Template definition that doesn\'t contain float can derive Hash/PartialOrd/Ord/PartialEq/Eq"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct foo { @@ -17,7 +14,7 @@ impl Default for foo { unsafe { ::std::mem::zeroed() } } } -/// Can derive Hash/PartialOrd/Ord/PartialEq/Eq when instantiated with int +#[doc = " Can derive Hash/PartialOrd/Ord/PartialEq/Eq when instantiated with int"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct IntStr { @@ -46,7 +43,7 @@ impl Default for IntStr { unsafe { ::std::mem::zeroed() } } } -/// Cannot derive Hash/Eq/Ord when instantiated with float but can derive PartialEq/PartialOrd +#[doc = " Cannot derive Hash/Eq/Ord when instantiated with float but can derive PartialEq/PartialOrd"] #[repr(C)] #[derive(Debug, Copy, Clone, PartialOrd, PartialEq)] pub struct FloatStr { diff --git a/tests/expectations/tests/derive-partialeq-and-blacklist.rs b/tests/expectations/tests/derive-partialeq-and-blacklist.rs index 1c51c3a395..b6067e0e39 100644 --- a/tests/expectations/tests/derive-partialeq-and-blacklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blacklist.rs @@ -1,13 +1,10 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " Because this type contains a blacklisted type, it should not derive\n PartialEq."] #[repr(C)] pub struct ShouldNotDerivePartialEq { pub a: BlacklistMe, diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index a3715b0cc7..8da97aa3d5 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index 68344591a3..7d66194c20 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// Deriving PartialEq for rust unions is not supported. +#[doc = " Deriving PartialEq for rust unions is not supported."] #[repr(C)] #[derive(Copy, Clone)] pub union ShouldNotDerivePartialEq { diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index dab82854ec..9840ad697a 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -47,7 +45,7 @@ impl ::std::cmp::PartialEq for __BindgenUnionField { } } impl ::std::cmp::Eq for __BindgenUnionField {} -/// This should manually derive PartialEq. +#[doc = " This should manually derive PartialEq."] #[repr(C)] #[derive(Copy)] pub struct ShouldDerivePartialEq { 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 9709332180..b127f3d5a5 100644 --- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 cf576634ce..fad7607620 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Doggo { @@ -45,12 +43,7 @@ fn bindgen_test_layout_Null() { concat!("Alignment of ", stringify!(Null)) ); } -/// This type is an opaque union. Unions can't derive anything interesting like -/// Debug or Default, even if their layout can, because it would require knowing -/// which variant is in use. Opaque unions still end up as a `union` in the Rust -/// bindings, but they just have one variant. Even so, can't derive. We should -/// probably emit an opaque struct for opaque unions... but until then, we have -/// this test to make sure that opaque unions don't derive and still compile. +#[doc = " This type is an opaque union. Unions can\'t derive anything interesting like\n Debug or Default, even if their layout can, because it would require knowing\n which variant is in use. Opaque unions still end up as a `union` in the Rust\n bindings, but they just have one variant. Even so, can\'t derive. We should\n probably emit an opaque struct for opaque unions... but until then, we have\n this test to make sure that opaque unions don\'t derive and still compile."] #[repr(C)] #[derive(Copy, Clone)] pub union DoggoOrNull { diff --git a/tests/expectations/tests/enum-doc-bitfield.rs b/tests/expectations/tests/enum-doc-bitfield.rs index 93d1f5f080..f544e24614 100644 --- a/tests/expectations/tests/enum-doc-bitfield.rs +++ b/tests/expectations/tests/enum-doc-bitfield.rs @@ -3,30 +3,27 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl B { - /// Document field with three slashes + #[doc = " Document field with three slashes"] pub const VAR_A: B = B(0); } impl B { - /// Document field with preceeding star + #[doc = " Document field with preceeding star"] pub const VAR_B: B = B(1); } impl B { - /// Document field with preceeding exclamation + #[doc = " Document field with preceeding exclamation"] pub const VAR_C: B = B(2); } impl B { - /// < Document field with following star + #[doc = " < Document field with following star"] pub const VAR_D: B = B(3); } impl B { - /// < Document field with following exclamation + #[doc = " < Document field with following exclamation"] pub const VAR_E: B = B(4); } impl B { - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + #[doc = " Document field with preceeding star, with a loong long multiline\n comment.\n\n Very interesting documentation, definitely."] pub const VAR_F: B = B(5); } impl ::std::ops::BitOr for B { @@ -56,6 +53,6 @@ impl ::std::ops::BitAndAssign for B { } } #[repr(C)] -/// Document enum +#[doc = " Document enum"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct B(pub u32); diff --git a/tests/expectations/tests/enum-doc-mod.rs b/tests/expectations/tests/enum-doc-mod.rs index cb10bb3d6d..c1fdc52189 100644 --- a/tests/expectations/tests/enum-doc-mod.rs +++ b/tests/expectations/tests/enum-doc-mod.rs @@ -3,21 +3,18 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod B { - /// Document enum + #[doc = " Document enum"] pub type Type = u32; - /// Document field with three slashes + #[doc = " Document field with three slashes"] pub const VAR_A: Type = 0; - /// Document field with preceeding star + #[doc = " Document field with preceeding star"] pub const VAR_B: Type = 1; - /// Document field with preceeding exclamation + #[doc = " Document field with preceeding exclamation"] pub const VAR_C: Type = 2; - /// < Document field with following star + #[doc = " < Document field with following star"] pub const VAR_D: Type = 3; - /// < Document field with following exclamation + #[doc = " < Document field with following exclamation"] pub const VAR_E: Type = 4; - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + #[doc = " Document field with preceeding star, with a loong long multiline\n comment.\n \n Very interesting documentation, definitely."] pub const VAR_F: Type = 5; } diff --git a/tests/expectations/tests/enum-doc-rusty.rs b/tests/expectations/tests/enum-doc-rusty.rs index 2a57fb6436..b83adc1d12 100644 --- a/tests/expectations/tests/enum-doc-rusty.rs +++ b/tests/expectations/tests/enum-doc-rusty.rs @@ -3,22 +3,19 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] -/// Document enum +#[doc = " Document enum"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum B { - /// Document field with three slashes + #[doc = " Document field with three slashes"] VAR_A = 0, - /// Document field with preceeding star + #[doc = " Document field with preceeding star"] VAR_B = 1, - /// Document field with preceeding exclamation + #[doc = " Document field with preceeding exclamation"] VAR_C = 2, - /// < Document field with following star + #[doc = " < Document field with following star"] VAR_D = 3, - /// < Document field with following exclamation + #[doc = " < Document field with following exclamation"] VAR_E = 4, - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + #[doc = " Document field with preceeding star, with a loong long multiline\n comment.\n \n Very interesting documentation, definitely."] VAR_F = 5, } diff --git a/tests/expectations/tests/enum-doc.rs b/tests/expectations/tests/enum-doc.rs index e57728fb4f..2f53aa52df 100644 --- a/tests/expectations/tests/enum-doc.rs +++ b/tests/expectations/tests/enum-doc.rs @@ -2,20 +2,17 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -/// Document field with three slashes +#[doc = " Document field with three slashes"] pub const B_VAR_A: B = 0; -/// Document field with preceeding star +#[doc = " Document field with preceeding star"] pub const B_VAR_B: B = 1; -/// Document field with preceeding exclamation +#[doc = " Document field with preceeding exclamation"] pub const B_VAR_C: B = 2; -/// < Document field with following star +#[doc = " < Document field with following star"] pub const B_VAR_D: B = 3; -/// < Document field with following exclamation +#[doc = " < Document field with following exclamation"] pub const B_VAR_E: B = 4; -/// Document field with preceeding star, with a loong long multiline -/// comment. -/// -/// Very interesting documentation, definitely. +#[doc = " Document field with preceeding star, with a loong long multiline\n comment.\n\n Very interesting documentation, definitely."] pub const B_VAR_F: B = 5; -/// Document enum +#[doc = " Document enum"] pub type B = u32; diff --git a/tests/expectations/tests/enum-variant-replaces.rs b/tests/expectations/tests/enum-variant-replaces.rs index aabcad753f..c7847270a6 100644 --- a/tests/expectations/tests/enum-variant-replaces.rs +++ b/tests/expectations/tests/enum-variant-replaces.rs @@ -2,13 +2,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -///
-/// -/// Should see PASS below. +#[doc = "
\n\n Should see PASS below."] pub const OGRErr_PASS: OGRErr = 0; -///
-/// -/// Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below. +#[doc = "
\n\n Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below."] pub const OGRErr_OGRERR_NONE: OGRErr = 1; -///
+#[doc = "
"] pub type OGRErr = u32; 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 cf8b283c4b..21a3aebcf9 100644 --- a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -1,12 +1,10 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] pub struct BaseWithVtable__bindgen_vtable(::std::os::raw::c_void); -/// This should have an explicit vtable. +#[doc = " This should have an explicit vtable."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseWithVtable { @@ -19,7 +17,7 @@ impl Default for BaseWithVtable { unsafe { ::std::mem::zeroed() } } } -/// This should not have an explicit vtable. +#[doc = " This should not have an explicit vtable."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DerivedWithNoVirtualMethods { @@ -43,7 +41,7 @@ impl Default for DerivedWithNoVirtualMethods { unsafe { ::std::mem::zeroed() } } } -/// This should not have an explicit vtable. +#[doc = " This should not have an explicit vtable."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DerivedWithVirtualMethods { @@ -67,7 +65,7 @@ impl Default for DerivedWithVirtualMethods { unsafe { ::std::mem::zeroed() } } } -/// This should not have any vtable. +#[doc = " This should not have any vtable."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseWithoutVtable { @@ -81,7 +79,7 @@ impl Default for BaseWithoutVtable { } #[repr(C)] pub struct DerivedWithVtable__bindgen_vtable(::std::os::raw::c_void); -/// This should have an explicit vtable. +#[doc = " This should have an explicit vtable."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DerivedWithVtable { @@ -106,7 +104,7 @@ impl Default for DerivedWithVtable { unsafe { ::std::mem::zeroed() } } } -/// This should not have any vtable. +#[doc = " This should not have any vtable."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DerivedWithoutVtable { diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs index 687c430593..2f45b64c05 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 a8a520995e..55ba7f72f1 100644 --- a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 136f9e0c19..850a8be317 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -1,12 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " This should not be opaque; we can see the attributes and can pack the\n struct."] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToOne { @@ -35,8 +31,7 @@ fn bindgen_test_layout_AlignedToOne() { ) ); } -/// This should be opaque because although we can see the attributes, Rust -/// doesn't have `#[repr(packed = "N")]` yet. +#[doc = " This should be opaque because although we can see the attributes, Rust\n doesn\'t have `#[repr(packed = \"N\")]` yet."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { @@ -55,9 +50,7 @@ fn bindgen_test_layout_AlignedToTwo() { concat!("Alignment of ", stringify!(AlignedToTwo)) ); } -/// This should not be opaque because although `libclang` doesn't give us the -/// `#pragma pack(1)`, we can detect that alignment is 1 and add -/// `#[repr(packed)]` to the struct ourselves. +#[doc = " This should not be opaque because although `libclang` doesn\'t give us the\n `#pragma pack(1)`, we can detect that alignment is 1 and add\n `#[repr(packed)]` to the struct ourselves."] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToOne { @@ -97,9 +90,7 @@ fn bindgen_test_layout_PackedToOne() { ) ); } -/// In this case, even if we can detect the weird alignment triggered by -/// `#pragma pack(2)`, we can't do anything about it because Rust doesn't have -/// `#[repr(packed = "N")]`. Therefore, we must make it opaque. +#[doc = " In this case, even if we can detect the weird alignment triggered by\n `#pragma pack(2)`, we can\'t do anything about it because Rust doesn\'t have\n `#[repr(packed = \"N\")]`. Therefore, we must make it opaque."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToTwo { 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 0b0eb9a2da..e81af67b0c 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -1,14 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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 -/// up with the reight alignment, we're waiting on `#[repr(align="N")]` to land -/// in rustc). +#[doc = " We emit a `[u8; 63usize]` padding field for this struct, which cannot derive\n Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn\'t end\n up with the reight alignment, we\'re waiting on `#[repr(align=\"N\")]` to land\n in rustc)."] #[repr(C)] #[derive(Copy, Clone)] pub struct NoDebug { @@ -43,10 +37,7 @@ impl ::std::cmp::PartialEq for NoDebug { self.c == other.c } } -/// This should derive Debug/Hash/PartialEq/Eq because the padding size is less than the max derive -/// Debug/Hash/PartialEq/Eq impl for arrays. However, we conservatively don't derive Debug/Hash because -/// we determine Debug derive-ability before we compute padding, which happens at -/// codegen. (Again, we expect to get the alignment wrong for similar reasons.) +#[doc = " This should derive Debug/Hash/PartialEq/Eq because the padding size is less than the max derive\n Debug/Hash/PartialEq/Eq impl for arrays. However, we conservatively don\'t derive Debug/Hash because\n we determine Debug derive-ability before we compute padding, which happens at\n codegen. (Again, we expect to get the alignment wrong for similar reasons.)"] #[repr(C)] #[derive(Copy, Clone)] pub struct ShouldDeriveDebugButDoesNot { diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 81c32bbf33..afe574be62 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 555769a2ca..b99e5b046b 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 16fab93a10..61b6c65cc4 100644 --- a/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -1,16 +1,8 @@ /* automatically generated by rust-bindgen */ - #![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. -/// -/// See #848. -/// -///
+#[doc = " This is intended to replace another type, but won\'t if we treat this include\n as a system include, because clang doesn\'t parse comments there.\n\n See #848.\n\n
"] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { 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 8143921d9a..2570316bf4 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs @@ -1,12 +1,10 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " Because this type contains a blacklisted type, it should not derive Copy."] #[repr(C)] pub struct ShouldNotBeCopy { pub a: BlacklistMe, diff --git a/tests/expectations/tests/issue_315.rs b/tests/expectations/tests/issue_315.rs index d6660523b5..c4ce0d5851 100644 --- a/tests/expectations/tests/issue_315.rs +++ b/tests/expectations/tests/issue_315.rs @@ -1,9 +1,6 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] pub type c = a; diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 7e047f6aba..ab8ed1c7bc 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -128,43 +113,43 @@ pub enum JSValueShiftedTag { #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSWhyMagic { - /// a hole in a native object's elements + #[doc = " a hole in a native object\'s elements"] JS_ELEMENTS_HOLE = 0, - /// there is not a pending iterator value + #[doc = " there is not a pending iterator value"] JS_NO_ITER_VALUE = 1, - /// exception value thrown when closing a generator + #[doc = " exception value thrown when closing a generator"] JS_GENERATOR_CLOSING = 2, - /// compiler sentinel value + #[doc = " compiler sentinel value"] JS_NO_CONSTANT = 3, - /// used in debug builds to catch tracing errors + #[doc = " used in debug builds to catch tracing errors"] JS_THIS_POISON = 4, - /// used in debug builds to catch tracing errors + #[doc = " used in debug builds to catch tracing errors"] JS_ARG_POISON = 5, - /// an empty subnode in the AST serializer + #[doc = " an empty subnode in the AST serializer"] JS_SERIALIZE_NO_NODE = 6, - /// lazy arguments value on the stack + #[doc = " lazy arguments value on the stack"] JS_LAZY_ARGUMENTS = 7, - /// optimized-away 'arguments' value + #[doc = " optimized-away \'arguments\' value"] JS_OPTIMIZED_ARGUMENTS = 8, - /// magic value passed to natives to indicate construction + #[doc = " magic value passed to natives to indicate construction"] JS_IS_CONSTRUCTING = 9, - /// arguments.callee has been overwritten + #[doc = " arguments.callee has been overwritten"] JS_OVERWRITTEN_CALLEE = 10, - /// value of static block object slot + #[doc = " value of static block object slot"] JS_BLOCK_NEEDS_CLONE = 11, - /// see class js::HashableValue + #[doc = " see class js::HashableValue"] JS_HASH_KEY_EMPTY = 12, - /// error while running Ion code + #[doc = " error while running Ion code"] JS_ION_ERROR = 13, - /// missing recover instruction result + #[doc = " missing recover instruction result"] JS_ION_BAILOUT = 14, - /// optimized out slot + #[doc = " optimized out slot"] JS_OPTIMIZED_OUT = 15, - /// uninitialized lexical bindings that produce ReferenceError on touch. + #[doc = " uninitialized lexical bindings that produce ReferenceError on touch."] JS_UNINITIALIZED_LEXICAL = 16, - /// for local use + #[doc = " for local use"] JS_GENERIC_MAGIC = 17, - /// for local use + #[doc = " for local use"] JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 29ce27ad5b..7b225c985a 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -171,43 +156,43 @@ pub enum JSValueShiftedTag { #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSWhyMagic { - /// a hole in a native object's elements + #[doc = " a hole in a native object\'s elements"] JS_ELEMENTS_HOLE = 0, - /// there is not a pending iterator value + #[doc = " there is not a pending iterator value"] JS_NO_ITER_VALUE = 1, - /// exception value thrown when closing a generator + #[doc = " exception value thrown when closing a generator"] JS_GENERATOR_CLOSING = 2, - /// compiler sentinel value + #[doc = " compiler sentinel value"] JS_NO_CONSTANT = 3, - /// used in debug builds to catch tracing errors + #[doc = " used in debug builds to catch tracing errors"] JS_THIS_POISON = 4, - /// used in debug builds to catch tracing errors + #[doc = " used in debug builds to catch tracing errors"] JS_ARG_POISON = 5, - /// an empty subnode in the AST serializer + #[doc = " an empty subnode in the AST serializer"] JS_SERIALIZE_NO_NODE = 6, - /// lazy arguments value on the stack + #[doc = " lazy arguments value on the stack"] JS_LAZY_ARGUMENTS = 7, - /// optimized-away 'arguments' value + #[doc = " optimized-away \'arguments\' value"] JS_OPTIMIZED_ARGUMENTS = 8, - /// magic value passed to natives to indicate construction + #[doc = " magic value passed to natives to indicate construction"] JS_IS_CONSTRUCTING = 9, - /// arguments.callee has been overwritten + #[doc = " arguments.callee has been overwritten"] JS_OVERWRITTEN_CALLEE = 10, - /// value of static block object slot + #[doc = " value of static block object slot"] JS_BLOCK_NEEDS_CLONE = 11, - /// see class js::HashableValue + #[doc = " see class js::HashableValue"] JS_HASH_KEY_EMPTY = 12, - /// error while running Ion code + #[doc = " error while running Ion code"] JS_ION_ERROR = 13, - /// missing recover instruction result + #[doc = " missing recover instruction result"] JS_ION_BAILOUT = 14, - /// optimized out slot + #[doc = " optimized out slot"] JS_OPTIMIZED_OUT = 15, - /// uninitialized lexical bindings that produce ReferenceError on touch. + #[doc = " uninitialized lexical bindings that produce ReferenceError on touch."] JS_UNINITIALIZED_LEXICAL = 16, - /// for local use + #[doc = " for local use"] JS_GENERIC_MAGIC = 17, - /// for local use + #[doc = " for local use"] JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index a0f7f8ad3b..491972ce7e 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -123,15 +106,15 @@ impl ::std::marker::Copy for __IncompleteArrayField {} #[repr(C)] #[derive(Debug)] pub struct rte_kni_fifo { - /// < Next position to be written + #[doc = " < Next position to be written"] pub write: ::std::os::raw::c_uint, - /// < Next position to be read + #[doc = " < Next position to be read"] pub read: ::std::os::raw::c_uint, - /// < Circular buffer length + #[doc = " < Circular buffer length"] pub len: ::std::os::raw::c_uint, - /// < Pointer size - for 32/64 bit OS + #[doc = " < Pointer size - for 32/64 bit OS"] pub elem_size: ::std::os::raw::c_uint, - /// < The buffer contains mbuf pointers + #[doc = " < The buffer contains mbuf pointers"] pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, pub __bindgen_align: [u64; 0usize], } @@ -156,7 +139,7 @@ impl Default for rte_kni_fifo { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rte_eth_link { - /// < ETH_SPEED_NUM_ + #[doc = " < ETH_SPEED_NUM_"] pub link_speed: u32, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, pub __bindgen_padding_0: [u8; 3usize], diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index 7516f5e40e..8a193b6d80 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -10,19 +10,11 @@ pub const ARP_OP_REVREQUEST: u32 = 3; pub const ARP_OP_REVREPLY: u32 = 4; pub const ARP_OP_INVREQUEST: u32 = 8; pub const ARP_OP_INVREPLY: u32 = 9; -/// Ethernet address: -/// A universally administered address is uniquely assigned to a device by its -/// manufacturer. The first three octets (in transmission order) contain the -/// Organizationally Unique Identifier (OUI). The following three (MAC-48 and -/// EUI-48) octets are assigned by that organization with the only constraint -/// of uniqueness. -/// A locally administered address is assigned to a device by a network -/// administrator and does not contain OUIs. -/// See http://standards.ieee.org/regauth/groupmac/tutorial.html +#[doc = " Ethernet address:\n A universally administered address is uniquely assigned to a device by its\n manufacturer. The first three octets (in transmission order) contain the\n Organizationally Unique Identifier (OUI). The following three (MAC-48 and\n EUI-48) octets are assigned by that organization with the only constraint\n of uniqueness.\n A locally administered address is assigned to a device by a network\n administrator and does not contain OUIs.\n See http://standards.ieee.org/regauth/groupmac/tutorial.html"] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct ether_addr { - /// < Addr bytes in tx order + #[doc = " < Addr bytes in tx order"] pub addr_bytes: [u8; 6usize], } #[test] @@ -48,17 +40,17 @@ fn bindgen_test_layout_ether_addr() { ) ); } -/// ARP header IPv4 payload. +#[doc = " ARP header IPv4 payload."] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct arp_ipv4 { - /// < sender hardware address + #[doc = " < sender hardware address"] pub arp_sha: ether_addr, - /// < sender IP address + #[doc = " < sender IP address"] pub arp_sip: u32, - /// < target hardware address + #[doc = " < target hardware address"] pub arp_tha: ether_addr, - /// < target IP address + #[doc = " < target IP address"] pub arp_tip: u32, } #[test] @@ -114,7 +106,7 @@ fn bindgen_test_layout_arp_ipv4() { ) ); } -/// ARP header. +#[doc = " ARP header."] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct arp_hdr { diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 15fbfa42e4..bca0c89b2e 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -11,19 +11,12 @@ pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; pub struct rte_mempool { _unused: [u8; 0], } -/// Prototype for implementation specific data provisioning function. -/// -/// The function should provide the implementation specific memory for -/// for use by the other mempool ops functions in a given mempool ops struct. -/// E.g. the default ops provides an instance of the rte_ring for this purpose. -/// it will most likely point to a different type of data structure, and -/// will be transparent to the application programmer. -/// This function should set mp->pool_data. +#[doc = " Prototype for implementation specific data provisioning function.\n\n The function should provide the implementation specific memory for\n for use by the other mempool ops functions in a given mempool ops struct.\n E.g. the default ops provides an instance of the rte_ring for this purpose.\n it will most likely point to a different type of data structure, and\n will be transparent to the application programmer.\n This function should set mp->pool_data."] pub type rte_mempool_alloc_t = ::std::option::Option ::std::os::raw::c_int>; -/// Free the opaque private data pointed to by mp->pool_data pointer. +#[doc = " Free the opaque private data pointed to by mp->pool_data pointer."] pub type rte_mempool_free_t = ::std::option::Option; -/// Enqueue an object into the external pool. +#[doc = " Enqueue an object into the external pool."] pub type rte_mempool_enqueue_t = ::std::option::Option< unsafe extern "C" fn( mp: *mut rte_mempool, @@ -31,7 +24,7 @@ pub type rte_mempool_enqueue_t = ::std::option::Option< n: ::std::os::raw::c_uint, ) -> ::std::os::raw::c_int, >; -/// Dequeue an object from the external pool. +#[doc = " Dequeue an object from the external pool."] pub type rte_mempool_dequeue_t = ::std::option::Option< unsafe extern "C" fn( mp: *mut rte_mempool, @@ -39,24 +32,24 @@ pub type rte_mempool_dequeue_t = ::std::option::Option< n: ::std::os::raw::c_uint, ) -> ::std::os::raw::c_int, >; -/// Return the number of available objects in the external pool. +#[doc = " Return the number of available objects in the external pool."] pub type rte_mempool_get_count = ::std::option::Option ::std::os::raw::c_uint>; -/// Structure defining mempool operations structure +#[doc = " Structure defining mempool operations structure"] #[repr(C)] #[derive(Copy, Clone)] pub struct rte_mempool_ops { - /// < Name of mempool ops struct. + #[doc = " < Name of mempool ops struct."] pub name: [::std::os::raw::c_char; 32usize], - /// < Allocate private data. + #[doc = " < Allocate private data."] pub alloc: rte_mempool_alloc_t, - /// < Free the external pool. + #[doc = " < Free the external pool."] pub free: rte_mempool_free_t, - /// < Enqueue an object. + #[doc = " < Enqueue an object."] pub enqueue: rte_mempool_enqueue_t, - /// < Dequeue an object. + #[doc = " < Dequeue an object."] pub dequeue: rte_mempool_dequeue_t, - /// < Get qty of available objs. + #[doc = " < Get qty of available objs."] pub get_count: rte_mempool_get_count, pub __bindgen_padding_0: [u64; 7usize], } @@ -140,11 +133,11 @@ impl ::std::cmp::PartialEq for rte_mempool_ops { && self.get_count == other.get_count } } -/// The rte_spinlock_t type. +#[doc = " The rte_spinlock_t type."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_spinlock_t { - /// < lock status 0 = unlocked, 1 = locked + #[doc = " < lock status 0 = unlocked, 1 = locked"] pub locked: ::std::os::raw::c_int, } #[test] @@ -170,22 +163,16 @@ fn bindgen_test_layout_rte_spinlock_t() { ) ); } -/// Structure storing the table of registered ops structs, each of which contain -/// the function pointers for the mempool ops functions. -/// Each process has its own storage for this ops struct array so that -/// the mempools can be shared across primary and secondary processes. -/// The indices used to access the array are valid across processes, whereas -/// any function pointers stored directly in the mempool struct would not be. -/// This results in us simply having "ops_index" in the mempool struct. +#[doc = " Structure storing the table of registered ops structs, each of which contain\n the function pointers for the mempool ops functions.\n Each process has its own storage for this ops struct array so that\n the mempools can be shared across primary and secondary processes.\n The indices used to access the array are valid across processes, whereas\n any function pointers stored directly in the mempool struct would not be.\n This results in us simply having \"ops_index\" in the mempool struct."] #[repr(C)] #[derive(Copy, Clone)] pub struct rte_mempool_ops_table { - /// < Spinlock for add/delete. + #[doc = " < Spinlock for add/delete."] pub sl: rte_spinlock_t, - /// < Number of used ops structs in the table. + #[doc = " < Number of used ops structs in the table."] pub num_ops: u32, pub __bindgen_padding_0: [u64; 7usize], - /// Storage for all possible ops structs. + #[doc = " Storage for all possible ops structs."] pub ops: [rte_mempool_ops; 16usize], } #[test] @@ -231,7 +218,7 @@ impl Default for rte_mempool_ops_table { unsafe { ::std::mem::zeroed() } } } -/// Structure to hold malloc heap +#[doc = " Structure to hold malloc heap"] #[repr(C)] #[derive(Copy, Clone)] pub struct malloc_heap { diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 24ab41a478..bdaa0c915e 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -11,23 +11,23 @@ pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { - /// < index of last fragment + #[doc = " < index of last fragment"] IP_LAST_FRAG_IDX = 0, - /// < index of first fragment + #[doc = " < index of first fragment"] IP_FIRST_FRAG_IDX = 1, - /// < minimum number of fragments + #[doc = " < minimum number of fragments"] IP_MIN_FRAG_NUM = 2, IP_MAX_FRAG_NUM = 4, } -/// @internal fragmented mbuf +#[doc = " @internal fragmented mbuf"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ip_frag { - /// < offset into the packet + #[doc = " < offset into the packet"] pub ofs: u16, - /// < length of fragment + #[doc = " < length of fragment"] pub len: u16, - /// < fragment mbuf + #[doc = " < fragment mbuf"] pub mb: *mut rte_mbuf, } #[test] @@ -78,15 +78,15 @@ impl Default for ip_frag { unsafe { ::std::mem::zeroed() } } } -/// @internal to uniquely indetify fragmented datagram. +#[doc = " @internal to uniquely indetify fragmented datagram."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ip_frag_key { - /// < src address, first 8 bytes used for IPv4 + #[doc = " < src address, first 8 bytes used for IPv4"] pub src_dst: [u64; 4usize], - /// < dst address + #[doc = " < dst address"] pub id: u32, - /// < src/dst key length + #[doc = " < src/dst key length"] pub key_len: u32, } #[test] @@ -132,24 +132,23 @@ fn bindgen_test_layout_ip_frag_key() { ) ); } -/// @internal Fragmented packet to reassemble. -/// First two entries in the frags[] array are for the last and first fragments. +#[doc = " @internal Fragmented packet to reassemble.\n First two entries in the frags[] array are for the last and first fragments."] #[repr(C)] #[derive(Copy, Clone)] pub struct ip_frag_pkt { - /// < LRU list + #[doc = " < LRU list"] pub lru: ip_frag_pkt__bindgen_ty_1, - /// < fragmentation key + #[doc = " < fragmentation key"] pub key: ip_frag_key, - /// < creation timestamp + #[doc = " < creation timestamp"] pub start: u64, - /// < expected reassembled size + #[doc = " < expected reassembled size"] pub total_size: u32, - /// < size of fragments received + #[doc = " < size of fragments received"] pub frag_size: u32, - /// < index of next entry to fill + #[doc = " < index of next entry to fill"] pub last_idx: u32, - /// < fragments + #[doc = " < fragments"] pub frags: [ip_frag; 4usize], pub __bindgen_padding_0: [u64; 6usize], } @@ -291,7 +290,7 @@ impl ::std::cmp::PartialEq for ip_frag_pkt { && self.last_idx == other.last_idx && self.frags == other.frags } } -/// < fragment mbuf +#[doc = " < fragment mbuf"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf { diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index d583e641dc..17137baa82 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -2,8 +2,7 @@ #![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. +#[doc = " Stores a pointer to the ops struct, and the offset: the place to\n write the parsed result in the destination structure."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct cmdline_token_hdr { @@ -49,27 +48,11 @@ impl Default for cmdline_token_hdr { } } pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; -/// A token is defined by this structure. -/// -/// parse() takes the token as first argument, then the source buffer -/// starting at the token we want to parse. The 3rd arg is a pointer -/// where we store the parsed data (as binary). It returns the number of -/// parsed chars on success and a negative value on error. -/// -/// complete_get_nb() returns the number of possible values for this -/// token if completion is possible. If it is NULL or if it returns 0, -/// no completion is possible. -/// -/// complete_get_elt() copy in dstbuf (the size is specified in the -/// parameter) the i-th possible completion for this token. returns 0 -/// on success or and a negative value on error. -/// -/// get_help() fills the dstbuf with the help for the token. It returns -/// -1 on error and 0 on success. +#[doc = " A token is defined by this structure.\n\n parse() takes the token as first argument, then the source buffer\n starting at the token we want to parse. The 3rd arg is a pointer\n where we store the parsed data (as binary). It returns the number of\n parsed chars on success and a negative value on error.\n\n complete_get_nb() returns the number of possible values for this\n token if completion is possible. If it is NULL or if it returns 0,\n no completion is possible.\n\n complete_get_elt() copy in dstbuf (the size is specified in the\n parameter) the i-th possible completion for this token. returns 0\n on success or and a negative value on error.\n\n get_help() fills the dstbuf with the help for the token. It returns\n -1 on error and 0 on success."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct cmdline_token_ops { - /// parse(token ptr, buf, res pts, buf len) + #[doc = " parse(token ptr, buf, res pts, buf len)"] pub parse: ::std::option::Option< unsafe extern "C" fn( arg1: *mut cmdline_parse_token_hdr_t, @@ -78,11 +61,11 @@ pub struct cmdline_token_ops { arg4: ::std::os::raw::c_uint, ) -> ::std::os::raw::c_int, >, - /// return the num of possible choices for this token + #[doc = " return the num of possible choices for this token"] pub complete_get_nb: ::std::option::Option< unsafe extern "C" fn(arg1: *mut cmdline_parse_token_hdr_t) -> ::std::os::raw::c_int, >, - /// return the elt x for this token (token, idx, dstbuf, size) + #[doc = " return the elt x for this token (token, idx, dstbuf, size)"] pub complete_get_elt: ::std::option::Option< unsafe extern "C" fn( arg1: *mut cmdline_parse_token_hdr_t, @@ -91,7 +74,7 @@ pub struct cmdline_token_ops { arg4: ::std::os::raw::c_uint, ) -> ::std::os::raw::c_int, >, - /// get help for this token (token, dstbuf, size) + #[doc = " get help for this token (token, dstbuf, size)"] pub get_help: ::std::option::Option< unsafe extern "C" fn( arg1: *mut cmdline_parse_token_hdr_t, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 71d03ef64a..cac16d5ede 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -114,36 +99,35 @@ pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] -/// A set of values to identify what method is to be used to route -/// packets to multiple queues. +#[doc = " A set of values to identify what method is to be used to route\n packets to multiple queues."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_rx_mq_mode { - /// None of DCB,RSS or VMDQ mode + #[doc = " None of DCB,RSS or VMDQ mode"] ETH_MQ_RX_NONE = 0, - /// For RX side, only RSS is on + #[doc = " For RX side, only RSS is on"] ETH_MQ_RX_RSS = 1, - /// For RX side,only DCB is on. + #[doc = " For RX side,only DCB is on."] ETH_MQ_RX_DCB = 2, - /// Both DCB and RSS enable + #[doc = " Both DCB and RSS enable"] ETH_MQ_RX_DCB_RSS = 3, - /// Only VMDQ, no RSS nor DCB + #[doc = " Only VMDQ, no RSS nor DCB"] ETH_MQ_RX_VMDQ_ONLY = 4, - /// RSS mode with VMDQ + #[doc = " RSS mode with VMDQ"] ETH_MQ_RX_VMDQ_RSS = 5, - /// Use VMDQ+DCB to route traffic to queues + #[doc = " Use VMDQ+DCB to route traffic to queues"] ETH_MQ_RX_VMDQ_DCB = 6, - /// Enable both VMDQ and DCB in VMDq + #[doc = " Enable both VMDQ and DCB in VMDq"] ETH_MQ_RX_VMDQ_DCB_RSS = 7, } -/// A structure used to configure the RX features of an Ethernet port. +#[doc = " A structure used to configure the RX features of an Ethernet port."] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_rxmode { - /// The multi-queue packet distribution mode to be used, e.g. RSS. + #[doc = " The multi-queue packet distribution mode to be used, e.g. RSS."] pub mq_mode: rte_eth_rx_mq_mode, - /// < Only used if jumbo_frame enabled. + #[doc = " < Only used if jumbo_frame enabled."] pub max_rx_pkt_len: u32, - /// < hdr buf size (header_split enabled). + #[doc = " < hdr buf size (header_split enabled)."] pub split_hdr_size: u16, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, } @@ -349,24 +333,23 @@ impl rte_eth_rxmode { } } #[repr(u32)] -/// A set of values to identify what method is to be used to transmit -/// packets using multi-TCs. +#[doc = " A set of values to identify what method is to be used to transmit\n packets using multi-TCs."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_tx_mq_mode { - /// < It is in neither DCB nor VT mode. + #[doc = " < It is in neither DCB nor VT mode."] ETH_MQ_TX_NONE = 0, - /// < For TX side,only DCB is on. + #[doc = " < For TX side,only DCB is on."] ETH_MQ_TX_DCB = 1, - /// < For TX side,both DCB and VT is on. + #[doc = " < For TX side,both DCB and VT is on."] ETH_MQ_TX_VMDQ_DCB = 2, - /// < Only VT on, no DCB + #[doc = " < Only VT on, no DCB"] ETH_MQ_TX_VMDQ_ONLY = 3, } -/// A structure used to configure the TX features of an Ethernet port. +#[doc = " A structure used to configure the TX features of an Ethernet port."] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_txmode { - /// < TX multi-queues mode. + #[doc = " < TX multi-queues mode."] pub mq_mode: rte_eth_tx_mq_mode, pub pvid: u16, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, @@ -468,29 +451,15 @@ impl rte_eth_txmode { __bindgen_bitfield_unit } } -/// A structure used to configure the Receive Side Scaling (RSS) feature -/// of an Ethernet port. -/// If not NULL, the *rss_key* pointer of the *rss_conf* structure points -/// to an array holding the RSS key to use for hashing specific header -/// fields of received packets. The length of this array should be indicated -/// by *rss_key_len* below. Otherwise, a default random hash key is used by -/// the device driver. -/// -/// The *rss_key_len* field of the *rss_conf* structure indicates the length -/// in bytes of the array pointed by *rss_key*. To be compatible, this length -/// will be checked in i40e only. Others assume 40 bytes to be used as before. -/// -/// The *rss_hf* field of the *rss_conf* structure indicates the different -/// types of IPv4/IPv6 packets to which the RSS hashing must be applied. -/// Supplying an *rss_hf* equal to zero disables the RSS feature. +#[doc = " A structure used to configure the Receive Side Scaling (RSS) feature\n of an Ethernet port.\n If not NULL, the *rss_key* pointer of the *rss_conf* structure points\n to an array holding the RSS key to use for hashing specific header\n fields of received packets. The length of this array should be indicated\n by *rss_key_len* below. Otherwise, a default random hash key is used by\n the device driver.\n\n The *rss_key_len* field of the *rss_conf* structure indicates the length\n in bytes of the array pointed by *rss_key*. To be compatible, this length\n will be checked in i40e only. Others assume 40 bytes to be used as before.\n\n The *rss_hf* field of the *rss_conf* structure indicates the different\n types of IPv4/IPv6 packets to which the RSS hashing must be applied.\n Supplying an *rss_hf* equal to zero disables the RSS feature."] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { - /// < If not NULL, 40-byte hash key. + #[doc = " < If not NULL, 40-byte hash key."] pub rss_key: *mut u8, - /// < hash key length in bytes. + #[doc = " < hash key length in bytes."] pub rss_key_len: u8, - /// < Hash functions to apply - see below. + #[doc = " < Hash functions to apply - see below."] pub rss_hf: u64, } #[test] @@ -542,59 +511,49 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] -/// This enum indicates the possible number of traffic classes -/// in DCB configratioins +#[doc = " This enum indicates the possible number of traffic classes\n in DCB configratioins"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_nb_tcs { - /// < 4 TCs with DCB. + #[doc = " < 4 TCs with DCB."] ETH_4_TCS = 4, - /// < 8 TCs with DCB. + #[doc = " < 8 TCs with DCB."] ETH_8_TCS = 8, } #[repr(u32)] -/// This enum indicates the possible number of queue pools -/// in VMDQ configurations. +#[doc = " This enum indicates the possible number of queue pools\n in VMDQ configurations."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_nb_pools { - /// < 8 VMDq pools. + #[doc = " < 8 VMDq pools."] ETH_8_POOLS = 8, - /// < 16 VMDq pools. + #[doc = " < 16 VMDq pools."] ETH_16_POOLS = 16, - /// < 32 VMDq pools. + #[doc = " < 32 VMDq pools."] ETH_32_POOLS = 32, - /// < 64 VMDq pools. + #[doc = " < 64 VMDq pools."] ETH_64_POOLS = 64, } -/// A structure used to configure the VMDQ+DCB feature -/// of an Ethernet port. -/// -/// Using this feature, packets are routed to a pool of queues, based -/// on the vlan id in the vlan tag, and then to a specific queue within -/// that pool, using the user priority vlan tag field. -/// -/// A default pool may be used, if desired, to route all traffic which -/// does not match the vlan filter rules. +#[doc = " A structure used to configure the VMDQ+DCB feature\n of an Ethernet port.\n\n Using this feature, packets are routed to a pool of queues, based\n on the vlan id in the vlan tag, and then to a specific queue within\n that pool, using the user priority vlan tag field.\n\n A default pool may be used, if desired, to route all traffic which\n does not match the vlan filter rules."] #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_vmdq_dcb_conf { - /// < With DCB, 16 or 32 pools + #[doc = " < With DCB, 16 or 32 pools"] pub nb_queue_pools: rte_eth_nb_pools, - /// < If non-zero, use a default pool + #[doc = " < If non-zero, use a default pool"] pub enable_default_pool: u8, - /// < The default pool, if applicable + #[doc = " < The default pool, if applicable"] pub default_pool: u8, - /// < We can have up to 64 filters/mappings + #[doc = " < We can have up to 64 filters/mappings"] pub nb_pool_maps: u8, - /// < VMDq vlan pool maps. + #[doc = " < VMDq vlan pool maps."] pub pool_map: [rte_eth_vmdq_dcb_conf__bindgen_ty_1; 64usize], pub dcb_tc: [u8; 8usize], } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - /// < The vlan id of the received frame + #[doc = " < The vlan id of the received frame"] pub vlan_id: u16, - /// < Bitmask of pools for packet rx + #[doc = " < Bitmask of pools for packet rx"] pub pools: u64, } #[test] @@ -729,9 +688,9 @@ impl Default for rte_eth_vmdq_dcb_conf { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_dcb_rx_conf { - /// < Possible DCB TCs, 4 or 8 TCs + #[doc = " < Possible DCB TCs, 4 or 8 TCs"] pub nb_tcs: rte_eth_nb_tcs, - /// Traffic class each UP mapped to. + #[doc = " Traffic class each UP mapped to."] pub dcb_tc: [u8; 8usize], } #[test] @@ -775,9 +734,9 @@ impl Default for rte_eth_dcb_rx_conf { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_tx_conf { - /// < With DCB, 16 or 32 pools. + #[doc = " < With DCB, 16 or 32 pools."] pub nb_queue_pools: rte_eth_nb_pools, - /// Traffic class each UP mapped to. + #[doc = " Traffic class each UP mapped to."] pub dcb_tc: [u8; 8usize], } #[test] @@ -823,9 +782,9 @@ impl Default for rte_eth_vmdq_dcb_tx_conf { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_dcb_tx_conf { - /// < Possible DCB TCs, 4 or 8 TCs. + #[doc = " < Possible DCB TCs, 4 or 8 TCs."] pub nb_tcs: rte_eth_nb_tcs, - /// Traffic class each UP mapped to. + #[doc = " Traffic class each UP mapped to."] pub dcb_tc: [u8; 8usize], } #[test] @@ -869,7 +828,7 @@ impl Default for rte_eth_dcb_tx_conf { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_tx_conf { - /// < VMDq mode, 64 pools. + #[doc = " < VMDq mode, 64 pools."] pub nb_queue_pools: rte_eth_nb_pools, } #[test] @@ -905,27 +864,27 @@ impl Default for rte_eth_vmdq_tx_conf { #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_vmdq_rx_conf { - /// < VMDq only mode, 8 or 64 pools + #[doc = " < VMDq only mode, 8 or 64 pools"] pub nb_queue_pools: rte_eth_nb_pools, - /// < If non-zero, use a default pool + #[doc = " < If non-zero, use a default pool"] pub enable_default_pool: u8, - /// < The default pool, if applicable + #[doc = " < The default pool, if applicable"] pub default_pool: u8, - /// < Enable VT loop back + #[doc = " < Enable VT loop back"] pub enable_loop_back: u8, - /// < We can have up to 64 filters/mappings + #[doc = " < We can have up to 64 filters/mappings"] pub nb_pool_maps: u8, - /// < Flags from ETH_VMDQ_ACCEPT_* + #[doc = " < Flags from ETH_VMDQ_ACCEPT_*"] pub rx_mode: u32, - /// < VMDq vlan pool maps. + #[doc = " < VMDq vlan pool maps."] pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - /// < The vlan id of the received frame + #[doc = " < The vlan id of the received frame"] pub vlan_id: u16, - /// < Bitmask of pools for packet rx + #[doc = " < Bitmask of pools for packet rx"] pub pools: u64, } #[test] @@ -1070,56 +1029,55 @@ impl Default for rte_eth_vmdq_rx_conf { } } #[repr(u32)] -/// Flow Director setting modes: none, signature or perfect. +#[doc = " Flow Director setting modes: none, signature or perfect."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_mode { - /// < Disable FDIR support. + #[doc = " < Disable FDIR support."] RTE_FDIR_MODE_NONE = 0, - /// < Enable FDIR signature filter mode. + #[doc = " < Enable FDIR signature filter mode."] RTE_FDIR_MODE_SIGNATURE = 1, - /// < Enable FDIR perfect filter mode. + #[doc = " < Enable FDIR perfect filter mode."] RTE_FDIR_MODE_PERFECT = 2, - /// < Enable FDIR filter mode - MAC VLAN. + #[doc = " < Enable FDIR filter mode - MAC VLAN."] RTE_FDIR_MODE_PERFECT_MAC_VLAN = 3, - /// < Enable FDIR filter mode - tunnel. + #[doc = " < Enable FDIR filter mode - tunnel."] RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] -/// Memory space that can be configured to store Flow Director filters -/// in the board memory. +#[doc = " Memory space that can be configured to store Flow Director filters\n in the board memory."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_pballoc_type { - /// < 64k. + #[doc = " < 64k."] RTE_FDIR_PBALLOC_64K = 0, - /// < 128k. + #[doc = " < 128k."] RTE_FDIR_PBALLOC_128K = 1, - /// < 256k. + #[doc = " < 256k."] RTE_FDIR_PBALLOC_256K = 2, } #[repr(u32)] -/// Select report mode of FDIR hash information in RX descriptors. +#[doc = " Select report mode of FDIR hash information in RX descriptors."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_status_mode { - /// < Never report FDIR hash. + #[doc = " < Never report FDIR hash."] RTE_FDIR_NO_REPORT_STATUS = 0, - /// < Only report FDIR hash for matching pkts. + #[doc = " < Only report FDIR hash for matching pkts."] RTE_FDIR_REPORT_STATUS = 1, - /// < Always report FDIR hash. + #[doc = " < Always report FDIR hash."] RTE_FDIR_REPORT_STATUS_ALWAYS = 2, } -/// A structure used to define the input for IPV4 flow +#[doc = " A structure used to define the input for IPV4 flow"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_ipv4_flow { - /// < IPv4 source address in big endian. + #[doc = " < IPv4 source address in big endian."] pub src_ip: u32, - /// < IPv4 destination address in big endian. + #[doc = " < IPv4 destination address in big endian."] pub dst_ip: u32, - /// < Type of service to match. + #[doc = " < Type of service to match."] pub tos: u8, - /// < Time to live to match. + #[doc = " < Time to live to match."] pub ttl: u8, - /// < Protocol, next header in big endian. + #[doc = " < Protocol, next header in big endian."] pub proto: u8, } #[test] @@ -1185,19 +1143,19 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); } -/// A structure used to define the input for IPV6 flow +#[doc = " A structure used to define the input for IPV6 flow"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_ipv6_flow { - /// < IPv6 source address in big endian. + #[doc = " < IPv6 source address in big endian."] pub src_ip: [u32; 4usize], - /// < IPv6 destination address in big endian. + #[doc = " < IPv6 destination address in big endian."] pub dst_ip: [u32; 4usize], - /// < Traffic class to match. + #[doc = " < Traffic class to match."] pub tc: u8, - /// < Protocol, next header to match. + #[doc = " < Protocol, next header to match."] pub proto: u8, - /// < Hop limits to match. + #[doc = " < Hop limits to match."] pub hop_limits: u8, } #[test] @@ -1263,28 +1221,25 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); } -/// A structure used to configure FDIR masks that are used by the device -/// to match the various fields of RX packet headers. +#[doc = " A structure used to configure FDIR masks that are used by the device\n to match the various fields of RX packet headers."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { - /// < Bit mask for vlan_tci in big endian + #[doc = " < Bit mask for vlan_tci in big endian"] pub vlan_tci_mask: u16, - /// Bit mask for ipv4 flow in big endian. + #[doc = " Bit mask for ipv4 flow in big endian."] pub ipv4_mask: rte_eth_ipv4_flow, - /// Bit maks for ipv6 flow in big endian. + #[doc = " Bit maks for ipv6 flow in big endian."] pub ipv6_mask: rte_eth_ipv6_flow, - /// Bit mask for L4 source port in big endian. + #[doc = " Bit mask for L4 source port in big endian."] pub src_port_mask: u16, - /// Bit mask for L4 destination port in big endian. + #[doc = " Bit mask for L4 destination port in big endian."] pub dst_port_mask: u16, - /// 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - /// first byte on the wire + #[doc = " 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the\n first byte on the wire"] pub mac_addr_byte_mask: u8, - /// Bit mask for tunnel ID in big endian. + #[doc = " Bit mask for tunnel ID in big endian."] pub tunnel_id_mask: u32, - /// < 1 - Match tunnel type, - /// 0 - Ignore tunnel type. + #[doc = " < 1 - Match tunnel type,\n 0 - Ignore tunnel type."] pub tunnel_type_mask: u8, } #[test] @@ -1393,7 +1348,7 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); } #[repr(u32)] -/// Payload type +#[doc = " Payload type"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_payload_type { RTE_ETH_PAYLOAD_UNKNOWN = 0, @@ -1403,12 +1358,11 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -/// A structure used to select bytes extracted from the protocol layers to -/// flexible payload for filter +#[doc = " A structure used to select bytes extracted from the protocol layers to\n flexible payload for filter"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { - /// < Payload type + #[doc = " < Payload type"] pub type_: rte_eth_payload_type, pub src_offset: [u16; 16usize], } @@ -1452,8 +1406,7 @@ impl Default for rte_eth_flex_payload_cfg { unsafe { ::std::mem::zeroed() } } } -/// A structure used to define FDIR masks for flexible payload -/// for each flow type +#[doc = " A structure used to define FDIR masks for flexible payload\n for each flow type"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { @@ -1495,14 +1448,13 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ) ); } -/// A structure used to define all flexible payload related setting -/// include flex payload and flex mask +#[doc = " A structure used to define all flexible payload related setting\n include flex payload and flex mask"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { - /// < The number of following payload cfg + #[doc = " < The number of following payload cfg"] pub nb_payloads: u16, - /// < The number of following mask + #[doc = " < The number of following mask"] pub nb_flexmasks: u16, pub flex_set: [rte_eth_flex_payload_cfg; 8usize], pub flex_mask: [rte_eth_fdir_flex_mask; 22usize], @@ -1571,20 +1523,17 @@ impl Default for rte_eth_fdir_flex_conf { unsafe { ::std::mem::zeroed() } } } -/// A structure used to configure the Flow Director (FDIR) feature -/// of an Ethernet port. -/// -/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. +#[doc = " A structure used to configure the Flow Director (FDIR) feature\n of an Ethernet port.\n\n If mode is RTE_FDIR_DISABLE, the pballoc value is ignored."] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { - /// < Flow Director mode. + #[doc = " < Flow Director mode."] pub mode: rte_fdir_mode, - /// < Space for FDIR filters. + #[doc = " < Space for FDIR filters."] pub pballoc: rte_fdir_pballoc_type, - /// < How to report FDIR hash. + #[doc = " < How to report FDIR hash."] pub status: rte_fdir_status_mode, - /// RX queue of packets matching a "drop" filter in perfect mode. + #[doc = " RX queue of packets matching a \"drop\" filter in perfect mode."] pub drop_queue: u8, pub mask: rte_eth_fdir_masks, pub flex_conf: rte_eth_fdir_flex_conf, @@ -1667,13 +1616,13 @@ impl Default for rte_fdir_conf { unsafe { ::std::mem::zeroed() } } } -/// A structure used to enable/disable specific device interrupts. +#[doc = " A structure used to enable/disable specific device interrupts."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_intr_conf { - /// enable/disable lsc interrupt. 0 (default) - disable, 1 enable + #[doc = " enable/disable lsc interrupt. 0 (default) - disable, 1 enable"] pub lsc: u16, - /// enable/disable rxq interrupt. 0 (default) - disable, 1 enable + #[doc = " enable/disable rxq interrupt. 0 (default) - disable, 1 enable"] pub rxq: u16, } #[test] @@ -1709,46 +1658,33 @@ fn bindgen_test_layout_rte_intr_conf() { ) ); } -/// A structure used to configure an Ethernet port. -/// Depending upon the RX multi-queue mode, extra advanced -/// configuration settings may be needed. +#[doc = " A structure used to configure an Ethernet port.\n Depending upon the RX multi-queue mode, extra advanced\n configuration settings may be needed."] #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_conf { - /// < bitmap of ETH_LINK_SPEED_XXX of speeds to be - /// used. ETH_LINK_SPEED_FIXED disables link - /// autonegotiation, and a unique speed shall be - /// set. Otherwise, the bitmap defines the set of - /// speeds to be advertised. If the special value - /// ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - /// supported are advertised. + #[doc = " < bitmap of ETH_LINK_SPEED_XXX of speeds to be\n used. ETH_LINK_SPEED_FIXED disables link\n autonegotiation, and a unique speed shall be\n set. Otherwise, the bitmap defines the set of\n speeds to be advertised. If the special value\n ETH_LINK_SPEED_AUTONEG (0) is used, all speeds\n supported are advertised."] pub link_speeds: u32, - /// < Port RX configuration. + #[doc = " < Port RX configuration."] pub rxmode: rte_eth_rxmode, - /// < Port TX configuration. + #[doc = " < Port TX configuration."] pub txmode: rte_eth_txmode, - /// < Loopback operation mode. By default the value - /// is 0, meaning the loopback mode is disabled. - /// Read the datasheet of given ethernet controller - /// for details. The possible values of this field - /// are defined in implementation of each driver. + #[doc = " < Loopback operation mode. By default the value\n is 0, meaning the loopback mode is disabled.\n Read the datasheet of given ethernet controller\n for details. The possible values of this field\n are defined in implementation of each driver."] pub lpbk_mode: u32, - /// < Port RX filtering configuration (union). + #[doc = " < Port RX filtering configuration (union)."] pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, - /// < Port TX DCB configuration (union). + #[doc = " < Port TX DCB configuration (union)."] pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /// Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - /// is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. + #[doc = " Currently,Priority Flow Control(PFC) are supported,if DCB with PFC\n is needed,and the variable must be set ETH_DCB_PFC_SUPPORT."] pub dcb_capability_en: u32, - /// < FDIR configuration. + #[doc = " < FDIR configuration."] pub fdir_conf: rte_fdir_conf, - /// < Interrupt mode configuration. + #[doc = " < Interrupt mode configuration."] pub intr_conf: rte_intr_conf, } #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_conf__bindgen_ty_1 { - /// < Port RSS configuration + #[doc = " < Port RSS configuration"] pub rss_conf: rte_eth_rss_conf, pub vmdq_dcb_conf: rte_eth_vmdq_dcb_conf, pub dcb_rx_conf: rte_eth_dcb_rx_conf, diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index e9a09f54ea..dd78addfcc 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -157,36 +142,35 @@ pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] -/// A set of values to identify what method is to be used to route -/// packets to multiple queues. +#[doc = " A set of values to identify what method is to be used to route\n packets to multiple queues."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_rx_mq_mode { - /// None of DCB,RSS or VMDQ mode + #[doc = " None of DCB,RSS or VMDQ mode"] ETH_MQ_RX_NONE = 0, - /// For RX side, only RSS is on + #[doc = " For RX side, only RSS is on"] ETH_MQ_RX_RSS = 1, - /// For RX side,only DCB is on. + #[doc = " For RX side,only DCB is on."] ETH_MQ_RX_DCB = 2, - /// Both DCB and RSS enable + #[doc = " Both DCB and RSS enable"] ETH_MQ_RX_DCB_RSS = 3, - /// Only VMDQ, no RSS nor DCB + #[doc = " Only VMDQ, no RSS nor DCB"] ETH_MQ_RX_VMDQ_ONLY = 4, - /// RSS mode with VMDQ + #[doc = " RSS mode with VMDQ"] ETH_MQ_RX_VMDQ_RSS = 5, - /// Use VMDQ+DCB to route traffic to queues + #[doc = " Use VMDQ+DCB to route traffic to queues"] ETH_MQ_RX_VMDQ_DCB = 6, - /// Enable both VMDQ and DCB in VMDq + #[doc = " Enable both VMDQ and DCB in VMDq"] ETH_MQ_RX_VMDQ_DCB_RSS = 7, } -/// A structure used to configure the RX features of an Ethernet port. +#[doc = " A structure used to configure the RX features of an Ethernet port."] #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_rxmode { - /// The multi-queue packet distribution mode to be used, e.g. RSS. + #[doc = " The multi-queue packet distribution mode to be used, e.g. RSS."] pub mq_mode: rte_eth_rx_mq_mode, - /// < Only used if jumbo_frame enabled. + #[doc = " < Only used if jumbo_frame enabled."] pub max_rx_pkt_len: u32, - /// < hdr buf size (header_split enabled). + #[doc = " < hdr buf size (header_split enabled)."] pub split_hdr_size: u16, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, } @@ -397,24 +381,23 @@ impl rte_eth_rxmode { } } #[repr(u32)] -/// A set of values to identify what method is to be used to transmit -/// packets using multi-TCs. +#[doc = " A set of values to identify what method is to be used to transmit\n packets using multi-TCs."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_tx_mq_mode { - /// < It is in neither DCB nor VT mode. + #[doc = " < It is in neither DCB nor VT mode."] ETH_MQ_TX_NONE = 0, - /// < For TX side,only DCB is on. + #[doc = " < For TX side,only DCB is on."] ETH_MQ_TX_DCB = 1, - /// < For TX side,both DCB and VT is on. + #[doc = " < For TX side,both DCB and VT is on."] ETH_MQ_TX_VMDQ_DCB = 2, - /// < Only VT on, no DCB + #[doc = " < Only VT on, no DCB"] ETH_MQ_TX_VMDQ_ONLY = 3, } -/// A structure used to configure the TX features of an Ethernet port. +#[doc = " A structure used to configure the TX features of an Ethernet port."] #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_txmode { - /// < TX multi-queues mode. + #[doc = " < TX multi-queues mode."] pub mq_mode: rte_eth_tx_mq_mode, pub pvid: u16, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, @@ -521,29 +504,15 @@ impl rte_eth_txmode { __bindgen_bitfield_unit } } -/// A structure used to configure the Receive Side Scaling (RSS) feature -/// of an Ethernet port. -/// If not NULL, the *rss_key* pointer of the *rss_conf* structure points -/// to an array holding the RSS key to use for hashing specific header -/// fields of received packets. The length of this array should be indicated -/// by *rss_key_len* below. Otherwise, a default random hash key is used by -/// the device driver. -/// -/// The *rss_key_len* field of the *rss_conf* structure indicates the length -/// in bytes of the array pointed by *rss_key*. To be compatible, this length -/// will be checked in i40e only. Others assume 40 bytes to be used as before. -/// -/// The *rss_hf* field of the *rss_conf* structure indicates the different -/// types of IPv4/IPv6 packets to which the RSS hashing must be applied. -/// Supplying an *rss_hf* equal to zero disables the RSS feature. +#[doc = " A structure used to configure the Receive Side Scaling (RSS) feature\n of an Ethernet port.\n If not NULL, the *rss_key* pointer of the *rss_conf* structure points\n to an array holding the RSS key to use for hashing specific header\n fields of received packets. The length of this array should be indicated\n by *rss_key_len* below. Otherwise, a default random hash key is used by\n the device driver.\n\n The *rss_key_len* field of the *rss_conf* structure indicates the length\n in bytes of the array pointed by *rss_key*. To be compatible, this length\n will be checked in i40e only. Others assume 40 bytes to be used as before.\n\n The *rss_hf* field of the *rss_conf* structure indicates the different\n types of IPv4/IPv6 packets to which the RSS hashing must be applied.\n Supplying an *rss_hf* equal to zero disables the RSS feature."] #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { - /// < If not NULL, 40-byte hash key. + #[doc = " < If not NULL, 40-byte hash key."] pub rss_key: *mut u8, - /// < hash key length in bytes. + #[doc = " < hash key length in bytes."] pub rss_key_len: u8, - /// < Hash functions to apply - see below. + #[doc = " < Hash functions to apply - see below."] pub rss_hf: u64, } #[test] @@ -600,59 +569,49 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] -/// This enum indicates the possible number of traffic classes -/// in DCB configratioins +#[doc = " This enum indicates the possible number of traffic classes\n in DCB configratioins"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_nb_tcs { - /// < 4 TCs with DCB. + #[doc = " < 4 TCs with DCB."] ETH_4_TCS = 4, - /// < 8 TCs with DCB. + #[doc = " < 8 TCs with DCB."] ETH_8_TCS = 8, } #[repr(u32)] -/// This enum indicates the possible number of queue pools -/// in VMDQ configurations. +#[doc = " This enum indicates the possible number of queue pools\n in VMDQ configurations."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_nb_pools { - /// < 8 VMDq pools. + #[doc = " < 8 VMDq pools."] ETH_8_POOLS = 8, - /// < 16 VMDq pools. + #[doc = " < 16 VMDq pools."] ETH_16_POOLS = 16, - /// < 32 VMDq pools. + #[doc = " < 32 VMDq pools."] ETH_32_POOLS = 32, - /// < 64 VMDq pools. + #[doc = " < 64 VMDq pools."] ETH_64_POOLS = 64, } -/// A structure used to configure the VMDQ+DCB feature -/// of an Ethernet port. -/// -/// Using this feature, packets are routed to a pool of queues, based -/// on the vlan id in the vlan tag, and then to a specific queue within -/// that pool, using the user priority vlan tag field. -/// -/// A default pool may be used, if desired, to route all traffic which -/// does not match the vlan filter rules. +#[doc = " A structure used to configure the VMDQ+DCB feature\n of an Ethernet port.\n\n Using this feature, packets are routed to a pool of queues, based\n on the vlan id in the vlan tag, and then to a specific queue within\n that pool, using the user priority vlan tag field.\n\n A default pool may be used, if desired, to route all traffic which\n does not match the vlan filter rules."] #[repr(C)] #[derive(Copy)] pub struct rte_eth_vmdq_dcb_conf { - /// < With DCB, 16 or 32 pools + #[doc = " < With DCB, 16 or 32 pools"] pub nb_queue_pools: rte_eth_nb_pools, - /// < If non-zero, use a default pool + #[doc = " < If non-zero, use a default pool"] pub enable_default_pool: u8, - /// < The default pool, if applicable + #[doc = " < The default pool, if applicable"] pub default_pool: u8, - /// < We can have up to 64 filters/mappings + #[doc = " < We can have up to 64 filters/mappings"] pub nb_pool_maps: u8, - /// < VMDq vlan pool maps. + #[doc = " < VMDq vlan pool maps."] pub pool_map: [rte_eth_vmdq_dcb_conf__bindgen_ty_1; 64usize], pub dcb_tc: [u8; 8usize], } #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - /// < The vlan id of the received frame + #[doc = " < The vlan id of the received frame"] pub vlan_id: u16, - /// < Bitmask of pools for packet rx + #[doc = " < Bitmask of pools for packet rx"] pub pools: u64, } #[test] @@ -797,9 +756,9 @@ impl Default for rte_eth_vmdq_dcb_conf { #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_dcb_rx_conf { - /// < Possible DCB TCs, 4 or 8 TCs + #[doc = " < Possible DCB TCs, 4 or 8 TCs"] pub nb_tcs: rte_eth_nb_tcs, - /// Traffic class each UP mapped to. + #[doc = " Traffic class each UP mapped to."] pub dcb_tc: [u8; 8usize], } #[test] @@ -848,9 +807,9 @@ impl Default for rte_eth_dcb_rx_conf { #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_tx_conf { - /// < With DCB, 16 or 32 pools. + #[doc = " < With DCB, 16 or 32 pools."] pub nb_queue_pools: rte_eth_nb_pools, - /// Traffic class each UP mapped to. + #[doc = " Traffic class each UP mapped to."] pub dcb_tc: [u8; 8usize], } #[test] @@ -901,9 +860,9 @@ impl Default for rte_eth_vmdq_dcb_tx_conf { #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_dcb_tx_conf { - /// < Possible DCB TCs, 4 or 8 TCs. + #[doc = " < Possible DCB TCs, 4 or 8 TCs."] pub nb_tcs: rte_eth_nb_tcs, - /// Traffic class each UP mapped to. + #[doc = " Traffic class each UP mapped to."] pub dcb_tc: [u8; 8usize], } #[test] @@ -952,7 +911,7 @@ impl Default for rte_eth_dcb_tx_conf { #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_tx_conf { - /// < VMDq mode, 64 pools. + #[doc = " < VMDq mode, 64 pools."] pub nb_queue_pools: rte_eth_nb_pools, } #[test] @@ -993,27 +952,27 @@ impl Default for rte_eth_vmdq_tx_conf { #[repr(C)] #[derive(Copy)] pub struct rte_eth_vmdq_rx_conf { - /// < VMDq only mode, 8 or 64 pools + #[doc = " < VMDq only mode, 8 or 64 pools"] pub nb_queue_pools: rte_eth_nb_pools, - /// < If non-zero, use a default pool + #[doc = " < If non-zero, use a default pool"] pub enable_default_pool: u8, - /// < The default pool, if applicable + #[doc = " < The default pool, if applicable"] pub default_pool: u8, - /// < Enable VT loop back + #[doc = " < Enable VT loop back"] pub enable_loop_back: u8, - /// < We can have up to 64 filters/mappings + #[doc = " < We can have up to 64 filters/mappings"] pub nb_pool_maps: u8, - /// < Flags from ETH_VMDQ_ACCEPT_* + #[doc = " < Flags from ETH_VMDQ_ACCEPT_*"] pub rx_mode: u32, - /// < VMDq vlan pool maps. + #[doc = " < VMDq vlan pool maps."] pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], } #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - /// < The vlan id of the received frame + #[doc = " < The vlan id of the received frame"] pub vlan_id: u16, - /// < Bitmask of pools for packet rx + #[doc = " < Bitmask of pools for packet rx"] pub pools: u64, } #[test] @@ -1168,56 +1127,55 @@ impl Default for rte_eth_vmdq_rx_conf { } } #[repr(u32)] -/// Flow Director setting modes: none, signature or perfect. +#[doc = " Flow Director setting modes: none, signature or perfect."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_mode { - /// < Disable FDIR support. + #[doc = " < Disable FDIR support."] RTE_FDIR_MODE_NONE = 0, - /// < Enable FDIR signature filter mode. + #[doc = " < Enable FDIR signature filter mode."] RTE_FDIR_MODE_SIGNATURE = 1, - /// < Enable FDIR perfect filter mode. + #[doc = " < Enable FDIR perfect filter mode."] RTE_FDIR_MODE_PERFECT = 2, - /// < Enable FDIR filter mode - MAC VLAN. + #[doc = " < Enable FDIR filter mode - MAC VLAN."] RTE_FDIR_MODE_PERFECT_MAC_VLAN = 3, - /// < Enable FDIR filter mode - tunnel. + #[doc = " < Enable FDIR filter mode - tunnel."] RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] -/// Memory space that can be configured to store Flow Director filters -/// in the board memory. +#[doc = " Memory space that can be configured to store Flow Director filters\n in the board memory."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_pballoc_type { - /// < 64k. + #[doc = " < 64k."] RTE_FDIR_PBALLOC_64K = 0, - /// < 128k. + #[doc = " < 128k."] RTE_FDIR_PBALLOC_128K = 1, - /// < 256k. + #[doc = " < 256k."] RTE_FDIR_PBALLOC_256K = 2, } #[repr(u32)] -/// Select report mode of FDIR hash information in RX descriptors. +#[doc = " Select report mode of FDIR hash information in RX descriptors."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_status_mode { - /// < Never report FDIR hash. + #[doc = " < Never report FDIR hash."] RTE_FDIR_NO_REPORT_STATUS = 0, - /// < Only report FDIR hash for matching pkts. + #[doc = " < Only report FDIR hash for matching pkts."] RTE_FDIR_REPORT_STATUS = 1, - /// < Always report FDIR hash. + #[doc = " < Always report FDIR hash."] RTE_FDIR_REPORT_STATUS_ALWAYS = 2, } -/// A structure used to define the input for IPV4 flow +#[doc = " A structure used to define the input for IPV4 flow"] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_ipv4_flow { - /// < IPv4 source address in big endian. + #[doc = " < IPv4 source address in big endian."] pub src_ip: u32, - /// < IPv4 destination address in big endian. + #[doc = " < IPv4 destination address in big endian."] pub dst_ip: u32, - /// < Type of service to match. + #[doc = " < Type of service to match."] pub tos: u8, - /// < Time to live to match. + #[doc = " < Time to live to match."] pub ttl: u8, - /// < Protocol, next header in big endian. + #[doc = " < Protocol, next header in big endian."] pub proto: u8, } #[test] @@ -1288,19 +1246,19 @@ impl Clone for rte_eth_ipv4_flow { *self } } -/// A structure used to define the input for IPV6 flow +#[doc = " A structure used to define the input for IPV6 flow"] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_ipv6_flow { - /// < IPv6 source address in big endian. + #[doc = " < IPv6 source address in big endian."] pub src_ip: [u32; 4usize], - /// < IPv6 destination address in big endian. + #[doc = " < IPv6 destination address in big endian."] pub dst_ip: [u32; 4usize], - /// < Traffic class to match. + #[doc = " < Traffic class to match."] pub tc: u8, - /// < Protocol, next header to match. + #[doc = " < Protocol, next header to match."] pub proto: u8, - /// < Hop limits to match. + #[doc = " < Hop limits to match."] pub hop_limits: u8, } #[test] @@ -1371,28 +1329,25 @@ impl Clone for rte_eth_ipv6_flow { *self } } -/// A structure used to configure FDIR masks that are used by the device -/// to match the various fields of RX packet headers. +#[doc = " A structure used to configure FDIR masks that are used by the device\n to match the various fields of RX packet headers."] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { - /// < Bit mask for vlan_tci in big endian + #[doc = " < Bit mask for vlan_tci in big endian"] pub vlan_tci_mask: u16, - /// Bit mask for ipv4 flow in big endian. + #[doc = " Bit mask for ipv4 flow in big endian."] pub ipv4_mask: rte_eth_ipv4_flow, - /// Bit maks for ipv6 flow in big endian. + #[doc = " Bit maks for ipv6 flow in big endian."] pub ipv6_mask: rte_eth_ipv6_flow, - /// Bit mask for L4 source port in big endian. + #[doc = " Bit mask for L4 source port in big endian."] pub src_port_mask: u16, - /// Bit mask for L4 destination port in big endian. + #[doc = " Bit mask for L4 destination port in big endian."] pub dst_port_mask: u16, - /// 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - /// first byte on the wire + #[doc = " 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the\n first byte on the wire"] pub mac_addr_byte_mask: u8, - /// Bit mask for tunnel ID in big endian. + #[doc = " Bit mask for tunnel ID in big endian."] pub tunnel_id_mask: u32, - /// < 1 - Match tunnel type, - /// 0 - Ignore tunnel type. + #[doc = " < 1 - Match tunnel type,\n 0 - Ignore tunnel type."] pub tunnel_type_mask: u8, } #[test] @@ -1506,7 +1461,7 @@ impl Clone for rte_eth_fdir_masks { } } #[repr(u32)] -/// Payload type +#[doc = " Payload type"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_payload_type { RTE_ETH_PAYLOAD_UNKNOWN = 0, @@ -1516,12 +1471,11 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -/// A structure used to select bytes extracted from the protocol layers to -/// flexible payload for filter +#[doc = " A structure used to select bytes extracted from the protocol layers to\n flexible payload for filter"] #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { - /// < Payload type + #[doc = " < Payload type"] pub type_: rte_eth_payload_type, pub src_offset: [u16; 16usize], } @@ -1570,8 +1524,7 @@ impl Default for rte_eth_flex_payload_cfg { unsafe { ::std::mem::zeroed() } } } -/// A structure used to define FDIR masks for flexible payload -/// for each flow type +#[doc = " A structure used to define FDIR masks for flexible payload\n for each flow type"] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { @@ -1618,14 +1571,13 @@ impl Clone for rte_eth_fdir_flex_mask { *self } } -/// A structure used to define all flexible payload related setting -/// include flex payload and flex mask +#[doc = " A structure used to define all flexible payload related setting\n include flex payload and flex mask"] #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { - /// < The number of following payload cfg + #[doc = " < The number of following payload cfg"] pub nb_payloads: u16, - /// < The number of following mask + #[doc = " < The number of following mask"] pub nb_flexmasks: u16, pub flex_set: [rte_eth_flex_payload_cfg; 8usize], pub flex_mask: [rte_eth_fdir_flex_mask; 22usize], @@ -1699,20 +1651,17 @@ impl Default for rte_eth_fdir_flex_conf { unsafe { ::std::mem::zeroed() } } } -/// A structure used to configure the Flow Director (FDIR) feature -/// of an Ethernet port. -/// -/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. +#[doc = " A structure used to configure the Flow Director (FDIR) feature\n of an Ethernet port.\n\n If mode is RTE_FDIR_DISABLE, the pballoc value is ignored."] #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { - /// < Flow Director mode. + #[doc = " < Flow Director mode."] pub mode: rte_fdir_mode, - /// < Space for FDIR filters. + #[doc = " < Space for FDIR filters."] pub pballoc: rte_fdir_pballoc_type, - /// < How to report FDIR hash. + #[doc = " < How to report FDIR hash."] pub status: rte_fdir_status_mode, - /// RX queue of packets matching a "drop" filter in perfect mode. + #[doc = " RX queue of packets matching a \"drop\" filter in perfect mode."] pub drop_queue: u8, pub mask: rte_eth_fdir_masks, pub flex_conf: rte_eth_fdir_flex_conf, @@ -1800,13 +1749,13 @@ impl Default for rte_fdir_conf { unsafe { ::std::mem::zeroed() } } } -/// A structure used to enable/disable specific device interrupts. +#[doc = " A structure used to enable/disable specific device interrupts."] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_intr_conf { - /// enable/disable lsc interrupt. 0 (default) - disable, 1 enable + #[doc = " enable/disable lsc interrupt. 0 (default) - disable, 1 enable"] pub lsc: u16, - /// enable/disable rxq interrupt. 0 (default) - disable, 1 enable + #[doc = " enable/disable rxq interrupt. 0 (default) - disable, 1 enable"] pub rxq: u16, } #[test] @@ -1847,46 +1796,33 @@ impl Clone for rte_intr_conf { *self } } -/// A structure used to configure an Ethernet port. -/// Depending upon the RX multi-queue mode, extra advanced -/// configuration settings may be needed. +#[doc = " A structure used to configure an Ethernet port.\n Depending upon the RX multi-queue mode, extra advanced\n configuration settings may be needed."] #[repr(C)] #[derive(Copy)] pub struct rte_eth_conf { - /// < bitmap of ETH_LINK_SPEED_XXX of speeds to be - /// used. ETH_LINK_SPEED_FIXED disables link - /// autonegotiation, and a unique speed shall be - /// set. Otherwise, the bitmap defines the set of - /// speeds to be advertised. If the special value - /// ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - /// supported are advertised. + #[doc = " < bitmap of ETH_LINK_SPEED_XXX of speeds to be\n used. ETH_LINK_SPEED_FIXED disables link\n autonegotiation, and a unique speed shall be\n set. Otherwise, the bitmap defines the set of\n speeds to be advertised. If the special value\n ETH_LINK_SPEED_AUTONEG (0) is used, all speeds\n supported are advertised."] pub link_speeds: u32, - /// < Port RX configuration. + #[doc = " < Port RX configuration."] pub rxmode: rte_eth_rxmode, - /// < Port TX configuration. + #[doc = " < Port TX configuration."] pub txmode: rte_eth_txmode, - /// < Loopback operation mode. By default the value - /// is 0, meaning the loopback mode is disabled. - /// Read the datasheet of given ethernet controller - /// for details. The possible values of this field - /// are defined in implementation of each driver. + #[doc = " < Loopback operation mode. By default the value\n is 0, meaning the loopback mode is disabled.\n Read the datasheet of given ethernet controller\n for details. The possible values of this field\n are defined in implementation of each driver."] pub lpbk_mode: u32, - /// < Port RX filtering configuration (union). + #[doc = " < Port RX filtering configuration (union)."] pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, - /// < Port TX DCB configuration (union). + #[doc = " < Port TX DCB configuration (union)."] pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /// Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - /// is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. + #[doc = " Currently,Priority Flow Control(PFC) are supported,if DCB with PFC\n is needed,and the variable must be set ETH_DCB_PFC_SUPPORT."] pub dcb_capability_en: u32, - /// < FDIR configuration. + #[doc = " < FDIR configuration."] pub fdir_conf: rte_fdir_conf, - /// < Interrupt mode configuration. + #[doc = " < Interrupt mode configuration."] pub intr_conf: rte_intr_conf, } #[repr(C)] #[derive(Copy)] pub struct rte_eth_conf__bindgen_ty_1 { - /// < Port RSS configuration + #[doc = " < Port RSS configuration"] pub rss_conf: rte_eth_rss_conf, pub vmdq_dcb_conf: rte_eth_vmdq_dcb_conf, pub dcb_rx_conf: rte_eth_dcb_rx_conf, diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index 80ab1be9a8..26d88c91af 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -10,18 +10,18 @@ pub struct rte_kni_mbuf { pub buf_addr: *mut ::std::os::raw::c_void, pub buf_physaddr: u64, pub pad0: [::std::os::raw::c_char; 2usize], - /// < Start address of data in segment buffer. + #[doc = " < Start address of data in segment buffer."] pub data_off: u16, pub pad1: [::std::os::raw::c_char; 2usize], - /// < Number of segments. + #[doc = " < Number of segments."] pub nb_segs: u8, pub pad4: [::std::os::raw::c_char; 1usize], - /// < Offload features. + #[doc = " < Offload features."] pub ol_flags: u64, pub pad2: [::std::os::raw::c_char; 4usize], - /// < Total pkt len: sum of all segment data_len. + #[doc = " < Total pkt len: sum of all segment data_len."] pub pkt_len: u32, - /// < Amount of data in segment buffer. + #[doc = " < Amount of data in segment buffer."] pub data_len: u16, pub __bindgen_padding_0: [u8; 22usize], pub pad3: [::std::os::raw::c_char; 8usize], diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index af738d04d8..adb3cd9cb8 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -48,23 +48,23 @@ pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { - /// < index of last fragment + #[doc = " < index of last fragment"] IP_LAST_FRAG_IDX = 0, - /// < index of first fragment + #[doc = " < index of first fragment"] IP_FIRST_FRAG_IDX = 1, - /// < minimum number of fragments + #[doc = " < minimum number of fragments"] IP_MIN_FRAG_NUM = 2, IP_MAX_FRAG_NUM = 4, } -/// @internal fragmented mbuf +#[doc = " @internal fragmented mbuf"] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ip_frag { - /// < offset into the packet + #[doc = " < offset into the packet"] pub ofs: u16, - /// < length of fragment + #[doc = " < length of fragment"] pub len: u16, - /// < fragment mbuf + #[doc = " < fragment mbuf"] pub mb: *mut rte_mbuf, } #[test] @@ -115,15 +115,15 @@ impl Default for ip_frag { unsafe { ::std::mem::zeroed() } } } -/// @internal to uniquely indetify fragmented datagram. +#[doc = " @internal to uniquely indetify fragmented datagram."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ip_frag_key { - /// < src address, first 8 bytes used for IPv4 + #[doc = " < src address, first 8 bytes used for IPv4"] pub src_dst: [u64; 4usize], - /// < dst address + #[doc = " < dst address"] pub id: u32, - /// < src/dst key length + #[doc = " < src/dst key length"] pub key_len: u32, } #[test] @@ -169,24 +169,23 @@ fn bindgen_test_layout_ip_frag_key() { ) ); } -/// @internal Fragmented packet to reassemble. -/// First two entries in the frags[] array are for the last and first fragments. +#[doc = " @internal Fragmented packet to reassemble.\n First two entries in the frags[] array are for the last and first fragments."] #[repr(C)] #[derive(Copy, Clone)] pub struct ip_frag_pkt { - /// < LRU list + #[doc = " < LRU list"] pub lru: ip_frag_pkt__bindgen_ty_1, - /// < fragmentation key + #[doc = " < fragmentation key"] pub key: ip_frag_key, - /// < creation timestamp + #[doc = " < creation timestamp"] pub start: u64, - /// < expected reassembled size + #[doc = " < expected reassembled size"] pub total_size: u32, - /// < size of fragments received + #[doc = " < size of fragments received"] pub frag_size: u32, - /// < index of next entry to fill + #[doc = " < index of next entry to fill"] pub last_idx: u32, - /// < fragments + #[doc = " < fragments"] pub frags: [ip_frag; 4usize], pub __bindgen_padding_0: [u64; 6usize], } @@ -365,21 +364,21 @@ impl Default for ip_pkt_list { unsafe { ::std::mem::zeroed() } } } -/// fragmentation table statistics +#[doc = " fragmentation table statistics"] #[repr(C)] #[derive(Copy, Clone)] pub struct ip_frag_tbl_stat { - /// < total # of find/insert attempts. + #[doc = " < total # of find/insert attempts."] pub find_num: u64, - /// < # of add ops. + #[doc = " < # of add ops."] pub add_num: u64, - /// < # of del ops. + #[doc = " < # of del ops."] pub del_num: u64, - /// < # of reuse (del/add) ops. + #[doc = " < # of reuse (del/add) ops."] pub reuse_num: u64, - /// < total # of add failures. + #[doc = " < total # of add failures."] pub fail_total: u64, - /// < # of 'no space' add failures. + #[doc = " < # of \'no space\' add failures."] pub fail_nospace: u64, pub __bindgen_padding_0: [u64; 2usize], } @@ -456,31 +455,31 @@ impl Default for ip_frag_tbl_stat { unsafe { ::std::mem::zeroed() } } } -/// fragmentation table +#[doc = " fragmentation table"] #[repr(C)] pub struct rte_ip_frag_tbl { - /// < ttl for table entries. + #[doc = " < ttl for table entries."] pub max_cycles: u64, - /// < hash value mask. + #[doc = " < hash value mask."] pub entry_mask: u32, - /// < max entries allowed. + #[doc = " < max entries allowed."] pub max_entries: u32, - /// < entries in use. + #[doc = " < entries in use."] pub use_entries: u32, - /// < hash assocaitivity. + #[doc = " < hash assocaitivity."] pub bucket_entries: u32, - /// < total size of the table. + #[doc = " < total size of the table."] pub nb_entries: u32, - /// < num of associativity lines. + #[doc = " < num of associativity lines."] pub nb_buckets: u32, - /// < last used entry. + #[doc = " < last used entry."] pub last: *mut ip_frag_pkt, - /// < LRU list for table entries. + #[doc = " < LRU list for table entries."] pub lru: ip_pkt_list, pub __bindgen_padding_0: u64, - /// < statistics counters. + #[doc = " < statistics counters."] pub stat: ip_frag_tbl_stat, - /// < hash table. + #[doc = " < hash table."] pub pkt: __IncompleteArrayField, } #[test] @@ -606,7 +605,7 @@ impl Default for rte_ip_frag_tbl { unsafe { ::std::mem::zeroed() } } } -/// < fragment mbuf +#[doc = " < fragment mbuf"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rte_mbuf { diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index c42cd0bad1..130efa6653 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -87,11 +72,11 @@ pub type phys_addr_t = u64; pub type MARKER = [*mut ::std::os::raw::c_void; 0usize]; pub type MARKER8 = [u8; 0usize]; pub type MARKER64 = [u64; 0usize]; -/// The atomic counter structure. +#[doc = " The atomic counter structure."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_atomic16_t { - /// < An internal counter value. + #[doc = " < An internal counter value."] pub cnt: i16, } #[test] @@ -117,65 +102,59 @@ fn bindgen_test_layout_rte_atomic16_t() { ) ); } -/// The generic rte_mbuf, containing a packet mbuf. +#[doc = " The generic rte_mbuf, containing a packet mbuf."] #[repr(C)] pub struct rte_mbuf { pub cacheline0: MARKER, - /// < Virtual address of segment buffer. + #[doc = " < Virtual address of segment buffer."] pub buf_addr: *mut ::std::os::raw::c_void, - /// < Physical address of segment buffer. + #[doc = " < Physical address of segment buffer."] pub buf_physaddr: phys_addr_t, - /// < Length of segment buffer. + #[doc = " < Length of segment buffer."] pub buf_len: u16, pub rearm_data: MARKER8, pub data_off: u16, pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, - /// < Number of segments. + #[doc = " < Number of segments."] pub nb_segs: u8, - /// < Input port. + #[doc = " < Input port."] pub port: u8, - /// < Offload features. + #[doc = " < Offload features."] pub ol_flags: u64, pub rx_descriptor_fields1: MARKER, pub __bindgen_anon_2: rte_mbuf__bindgen_ty_2, - /// < Total pkt len: sum of all segments. + #[doc = " < Total pkt len: sum of all segments."] pub pkt_len: u32, - /// < Amount of data in segment buffer. + #[doc = " < Amount of data in segment buffer."] pub data_len: u16, - /// VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set. + #[doc = " VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set."] pub vlan_tci: u16, - /// < hash information + #[doc = " < hash information"] pub hash: rte_mbuf__bindgen_ty_3, - /// < Sequence number. See also rte_reorder_insert() + #[doc = " < Sequence number. See also rte_reorder_insert()"] pub seqn: u32, - /// Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set. + #[doc = " Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set."] pub vlan_tci_outer: u16, pub cacheline1: MARKER, pub __bindgen_anon_3: rte_mbuf__bindgen_ty_4, - /// < Pool from which mbuf was allocated. + #[doc = " < Pool from which mbuf was allocated."] pub pool: *mut rte_mempool, - /// < Next segment of scattered packet. + #[doc = " < Next segment of scattered packet."] pub next: *mut rte_mbuf, pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /// Size of the application private data. In case of an indirect - /// mbuf, it stores the direct mbuf private data size. + #[doc = " Size of the application private data. In case of an indirect\n mbuf, it stores the direct mbuf private data size."] pub priv_size: u16, - /// Timesync flags for use with IEEE1588. + #[doc = " Timesync flags for use with IEEE1588."] pub timesync: u16, pub __bindgen_padding_0: [u32; 7usize], } -/// 16-bit Reference counter. -/// It should only be accessed using the following functions: -/// rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and -/// rte_mbuf_refcnt_set(). The functionality of these functions (atomic, -/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC -/// config option. +#[doc = " 16-bit Reference counter.\n It should only be accessed using the following functions:\n rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and\n rte_mbuf_refcnt_set(). The functionality of these functions (atomic,\n or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC\n config option."] #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { - /// < Atomically accessed refcnt + #[doc = " < Atomically accessed refcnt"] pub refcnt_atomic: rte_atomic16_t, - /// < Non-atomically accessed refcnt + #[doc = " < Non-atomically accessed refcnt"] pub refcnt: u16, _bindgen_union_align: u16, } @@ -222,7 +201,7 @@ impl Default for rte_mbuf__bindgen_ty_1 { #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_2 { - /// < L2/L3/L4 and tunnel information. + #[doc = " < L2/L3/L4 and tunnel information."] pub packet_type: u32, pub __bindgen_anon_1: rte_mbuf__bindgen_ty_2__bindgen_ty_1, _bindgen_union_align: u32, @@ -406,13 +385,13 @@ impl Default for rte_mbuf__bindgen_ty_2 { #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3 { - /// < RSS hash result if RSS enabled + #[doc = " < RSS hash result if RSS enabled"] pub rss: u32, - /// < Filter identifier if FDIR enabled + #[doc = " < Filter identifier if FDIR enabled"] pub fdir: rte_mbuf__bindgen_ty_3__bindgen_ty_1, - /// < Hierarchical scheduler + #[doc = " < Hierarchical scheduler"] pub sched: rte_mbuf__bindgen_ty_3__bindgen_ty_2, - /// < User defined tags. See rte_distributor_process() + #[doc = " < User defined tags. See rte_distributor_process()"] pub usr: u32, _bindgen_union_align: [u32; 2usize], } @@ -455,10 +434,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ); assert_eq!( unsafe { - &(*(::std::ptr::null::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >())) - .hash as *const _ as usize + &(*(::std::ptr::null::( + ))).hash as *const _ as usize }, 0usize, concat!( @@ -470,10 +447,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ); assert_eq!( unsafe { - &(*(::std::ptr::null::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >())) - .id as *const _ as usize + &(*(::std::ptr::null::( + ))).id as *const _ as usize }, 2usize, concat!( @@ -667,9 +642,9 @@ impl Default for rte_mbuf__bindgen_ty_3 { #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_4 { - /// < Can be used for external metadata + #[doc = " < Can be used for external metadata"] pub userdata: *mut ::std::os::raw::c_void, - /// < Allow 8-byte userdata on 32-bit + #[doc = " < Allow 8-byte userdata on 32-bit"] pub udata64: u64, _bindgen_union_align: u64, } @@ -714,7 +689,7 @@ impl Default for rte_mbuf__bindgen_ty_4 { #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_5 { - /// < combined for easy fetch + #[doc = " < combined for easy fetch"] pub tx_offload: u64, pub __bindgen_anon_1: rte_mbuf__bindgen_ty_5__bindgen_ty_1, _bindgen_union_align: u64, @@ -1102,7 +1077,7 @@ impl Default for rte_mbuf { unsafe { ::std::mem::zeroed() } } } -/// < Pool from which mbuf was allocated. +#[doc = " < Pool from which mbuf was allocated."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mempool { diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index 2fd5141897..2bb8d84779 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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; @@ -130,11 +115,11 @@ pub type phys_addr_t = u64; pub type MARKER = [*mut ::std::os::raw::c_void; 0usize]; pub type MARKER8 = [u8; 0usize]; pub type MARKER64 = [u64; 0usize]; -/// The atomic counter structure. +#[doc = " The atomic counter structure."] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_atomic16_t { - /// < An internal counter value. + #[doc = " < An internal counter value."] pub cnt: i16, } #[test] @@ -165,65 +150,59 @@ impl Clone for rte_atomic16_t { *self } } -/// The generic rte_mbuf, containing a packet mbuf. +#[doc = " The generic rte_mbuf, containing a packet mbuf."] #[repr(C)] pub struct rte_mbuf { pub cacheline0: MARKER, - /// < Virtual address of segment buffer. + #[doc = " < Virtual address of segment buffer."] pub buf_addr: *mut ::std::os::raw::c_void, - /// < Physical address of segment buffer. + #[doc = " < Physical address of segment buffer."] pub buf_physaddr: phys_addr_t, - /// < Length of segment buffer. + #[doc = " < Length of segment buffer."] pub buf_len: u16, pub rearm_data: MARKER8, pub data_off: u16, pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, - /// < Number of segments. + #[doc = " < Number of segments."] pub nb_segs: u8, - /// < Input port. + #[doc = " < Input port."] pub port: u8, - /// < Offload features. + #[doc = " < Offload features."] pub ol_flags: u64, pub rx_descriptor_fields1: MARKER, pub __bindgen_anon_2: rte_mbuf__bindgen_ty_2, - /// < Total pkt len: sum of all segments. + #[doc = " < Total pkt len: sum of all segments."] pub pkt_len: u32, - /// < Amount of data in segment buffer. + #[doc = " < Amount of data in segment buffer."] pub data_len: u16, - /// VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set. + #[doc = " VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set."] pub vlan_tci: u16, - /// < hash information + #[doc = " < hash information"] pub hash: rte_mbuf__bindgen_ty_3, - /// < Sequence number. See also rte_reorder_insert() + #[doc = " < Sequence number. See also rte_reorder_insert()"] pub seqn: u32, - /// Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set. + #[doc = " Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set."] pub vlan_tci_outer: u16, pub cacheline1: MARKER, pub __bindgen_anon_3: rte_mbuf__bindgen_ty_4, - /// < Pool from which mbuf was allocated. + #[doc = " < Pool from which mbuf was allocated."] pub pool: *mut rte_mempool, - /// < Next segment of scattered packet. + #[doc = " < Next segment of scattered packet."] pub next: *mut rte_mbuf, pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /// Size of the application private data. In case of an indirect - /// mbuf, it stores the direct mbuf private data size. + #[doc = " Size of the application private data. In case of an indirect\n mbuf, it stores the direct mbuf private data size."] pub priv_size: u16, - /// Timesync flags for use with IEEE1588. + #[doc = " Timesync flags for use with IEEE1588."] pub timesync: u16, pub __bindgen_padding_0: [u32; 7usize], } -/// 16-bit Reference counter. -/// It should only be accessed using the following functions: -/// rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and -/// rte_mbuf_refcnt_set(). The functionality of these functions (atomic, -/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC -/// config option. +#[doc = " 16-bit Reference counter.\n It should only be accessed using the following functions:\n rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and\n rte_mbuf_refcnt_set(). The functionality of these functions (atomic,\n or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC\n config option."] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_1 { - /// < Atomically accessed refcnt + #[doc = " < Atomically accessed refcnt"] pub refcnt_atomic: __BindgenUnionField, - /// < Non-atomically accessed refcnt + #[doc = " < Non-atomically accessed refcnt"] pub refcnt: __BindgenUnionField, pub bindgen_union_field: u16, } @@ -270,7 +249,7 @@ impl Clone for rte_mbuf__bindgen_ty_1 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_2 { - /// < L2/L3/L4 and tunnel information. + #[doc = " < L2/L3/L4 and tunnel information."] pub packet_type: __BindgenUnionField, pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, @@ -459,13 +438,13 @@ impl Clone for rte_mbuf__bindgen_ty_2 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_3 { - /// < RSS hash result if RSS enabled + #[doc = " < RSS hash result if RSS enabled"] pub rss: __BindgenUnionField, - /// < Filter identifier if FDIR enabled + #[doc = " < Filter identifier if FDIR enabled"] pub fdir: __BindgenUnionField, - /// < Hierarchical scheduler + #[doc = " < Hierarchical scheduler"] pub sched: __BindgenUnionField, - /// < User defined tags. See rte_distributor_process() + #[doc = " < User defined tags. See rte_distributor_process()"] pub usr: __BindgenUnionField, pub bindgen_union_field: [u32; 2usize], } @@ -509,10 +488,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ); assert_eq!( unsafe { - &(*(::std::ptr::null::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >())) - .hash as *const _ as usize + &(*(::std::ptr::null::( + ))).hash as *const _ as usize }, 0usize, concat!( @@ -524,10 +501,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ); assert_eq!( unsafe { - &(*(::std::ptr::null::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >())) - .id as *const _ as usize + &(*(::std::ptr::null::( + ))).id as *const _ as usize }, 2usize, concat!( @@ -731,9 +706,9 @@ impl Clone for rte_mbuf__bindgen_ty_3 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_4 { - /// < Can be used for external metadata + #[doc = " < Can be used for external metadata"] pub userdata: __BindgenUnionField<*mut ::std::os::raw::c_void>, - /// < Allow 8-byte userdata on 32-bit + #[doc = " < Allow 8-byte userdata on 32-bit"] pub udata64: __BindgenUnionField, pub bindgen_union_field: u64, } @@ -778,7 +753,7 @@ impl Clone for rte_mbuf__bindgen_ty_4 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_5 { - /// < combined for easy fetch + #[doc = " < combined for easy fetch"] pub tx_offload: __BindgenUnionField, pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u64, @@ -1171,7 +1146,7 @@ impl Default for rte_mbuf { unsafe { ::std::mem::zeroed() } } } -/// < Pool from which mbuf was allocated. +#[doc = " < Pool from which mbuf was allocated."] #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mempool { 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 a09323a8f2..851dc4e196 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { @@ -37,7 +35,7 @@ impl Default for Rooted { unsafe { ::std::mem::zeroed() } } } -///
+#[doc = "
"] pub type MaybeWrapped
= a; #[test] fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index 6272d7739b..9092304cee 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] @@ -9,10 +8,7 @@ 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. +#[doc = " bar should compile. It will normally derive debug, but our blacklist of foo\n and replacement for another type that doesn\'t implement it would prevent it\n from building if --no-derive-debug didn\'t work."] #[repr(C)] pub struct bar { pub foo: foo, diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index da5e10015d..83f0891df8 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] @@ -9,10 +8,7 @@ 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. +#[doc = " bar should compile. It will normally derive default, but our blacklist of foo\n and replacement for another type that doesn\'t implement it would prevent it\n from building if --no-derive-default didn\'t work."] #[repr(C)] pub struct bar { pub foo: foo, diff --git a/tests/expectations/tests/no_copy.rs b/tests/expectations/tests/no_copy.rs index 452496682d..96fd542c10 100644 --- a/tests/expectations/tests/no_copy.rs +++ b/tests/expectations/tests/no_copy.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default)] pub struct CopiableButWait { diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index 09bd8737ee..c7f6fc7aa5 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 99e507b86b..3e0b75e35e 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -1,18 +1,14 @@ /* automatically generated by rust-bindgen */ - #![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. +#[doc = " This is like `opaque-template-inst-member.hpp` except exercising the cases\n where we are OK to derive Debug/Hash/PartialEq."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { pub _address: u8, } -/// Should derive Debug/Hash/PartialEq. +#[doc = " Should derive Debug/Hash/PartialEq."] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsOpaqueTemplate { @@ -52,7 +48,7 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ) ); } -/// Should also derive Debug/Hash/PartialEq. +#[doc = " Should also derive Debug/Hash/PartialEq."] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct InheritsOpaqueTemplate { diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index 6653123240..5c4d8fd65b 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -1,16 +1,13 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { pub _address: u8, } -/// This should not end up deriving Debug/Hash because its `mBlah` field cannot derive -/// Debug/Hash because the instantiation's definition cannot derive Debug/Hash. +#[doc = " This should not end up deriving Debug/Hash because its `mBlah` field cannot derive\n Debug/Hash because the instantiation\'s definition cannot derive Debug/Hash."] #[repr(C)] pub struct ContainsOpaqueTemplate { pub mBlah: [u32; 101usize], @@ -59,8 +56,7 @@ impl ::std::cmp::PartialEq for ContainsOpaqueTemplate { &self.mBlah[..] == &other.mBlah[..] && self.mBaz == other.mBaz } } -/// This should not end up deriving Debug/Hash either, for similar reasons, although -/// we're exercising base member edges now. +#[doc = " This should not end up deriving Debug/Hash either, for similar reasons, although\n we\'re exercising base member edges now."] #[repr(C)] pub struct InheritsOpaqueTemplate { pub _base: [u8; 401usize], diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 5984858101..650edf6840 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct opaque { diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 736655a450..9dbce04357 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OtherOpaque { @@ -24,7 +21,7 @@ fn bindgen_test_layout_OtherOpaque() { concat!("Alignment of ", stringify!(OtherOpaque)) ); } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque { diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs index 96df276ccd..3f9defd37c 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -1,14 +1,12 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct RandomTemplate { pub _address: u8, } -///
+#[doc = "
"] pub type ShouldBeOpaque = u8; pub type ShouldNotBeOpaque = RandomTemplate; diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 52da1ae4ed..3329067c84 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -1,14 +1,12 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct HasPrivate { pub mNotPrivate: ::std::os::raw::c_int, - ///
+ #[doc = "
"] mIsPrivate: ::std::os::raw::c_int, } #[test] @@ -44,7 +42,7 @@ fn bindgen_test_layout_HasPrivate() { ) ); } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct VeryPrivate { @@ -84,11 +82,11 @@ fn bindgen_test_layout_VeryPrivate() { ) ); } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ContradictPrivate { - ///
+ #[doc = "
"] pub mNotPrivate: ::std::os::raw::c_int, mIsPrivate: ::std::os::raw::c_int, } diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index 38f0cc220a..374f2d4b61 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -11,7 +9,7 @@ pub mod root { pub mod foo { #[allow(unused_imports)] use self::super::super::root; - ///
+ #[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { diff --git a/tests/expectations/tests/replace_template_alias.rs b/tests/expectations/tests/replace_template_alias.rs index 3ddde177d5..2e973878fe 100644 --- a/tests/expectations/tests/replace_template_alias.rs +++ b/tests/expectations/tests/replace_template_alias.rs @@ -1,13 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// But the replacement type does use T! -/// -///
+#[doc = " But the replacement type does use T!\n\n
"] pub type JS_detail_MaybeWrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index c5184b7775..c188c27e4d 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -1,11 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsTArray { diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs index 9d49052e67..381e17e79e 100644 --- a/tests/expectations/tests/replaces_double.rs +++ b/tests/expectations/tests/replaces_double.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Wrapper_Wrapped { @@ -22,7 +20,7 @@ pub struct Rooted { pub ptr: Rooted_MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -///
+#[doc = "
"] pub type Rooted_MaybeWrapped = T; impl Default for Rooted { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index a45472d5a9..b6704f29bc 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 6083265cf5..3d089cee5e 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -326,7 +326,7 @@ impl Default for PODButContainsDtor { unsafe { ::std::mem::zeroed() } } } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque { @@ -360,7 +360,7 @@ fn bindgen_test_layout_POD() { ) ); } -///
+#[doc = "
"] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedReplaced { @@ -430,10 +430,7 @@ fn bindgen_test_layout_Untemplated() { pub struct Templated { pub m_untemplated: Untemplated, } -/// If the replacement doesn't happen at the parse level the container would be -/// copy and the replacement wouldn't, so this wouldn't compile. -/// -///
+#[doc = " If the replacement doesn\'t happen at the parse level the container would be\n copy and the replacement wouldn\'t, so this wouldn\'t compile.\n\n
"] #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructor { @@ -467,10 +464,7 @@ impl Default for ShouldNotBeCopiableAsWell { unsafe { ::std::mem::zeroed() } } } -/// If the replacement doesn't happen at the parse level the container would be -/// copy and the replacement wouldn't, so this wouldn't compile. -/// -///
+#[doc = " If the replacement doesn\'t happen at the parse level the container would be\n copy and the replacement wouldn\'t, so this wouldn\'t compile.\n\n
"] #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructorFwd { diff --git a/tests/expectations/tests/templatized-bitfield.rs b/tests/expectations/tests/templatized-bitfield.rs index 68ab6716fd..6b40b46a7b 100644 --- a/tests/expectations/tests/templatized-bitfield.rs +++ b/tests/expectations/tests/templatized-bitfield.rs @@ -1,13 +1,8 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - - -/// We don't get a layout for this bitfield, since we don't know what `T` will -/// be, so we cannot allocate bitfield units. The best thing we can do is make -/// the struct opaque. +#[doc = " We don\'t get a layout for this bitfield, since we don\'t know what `T` will\n be, so we cannot allocate bitfield units. The best thing we can do is make\n the struct opaque."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TemplatizedBitfield { diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index 1f75ee4de3..300008f6ab 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 a85fad4c2e..ee560e3e73 100644 --- a/tests/expectations/tests/union_bitfield_1_0.rs +++ b/tests/expectations/tests/union_bitfield_1_0.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 9e6717415e..30d05e8393 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 f2d63c3e8c..d13d723879 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,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit @@ -13,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -22,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 8ab2987cf6..72f0e5784d 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -11,7 +11,6 @@ where storage: Storage, align: [Align; 0], } - impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, @@ -20,60 +19,46 @@ 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 = 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 = index % 8; let mask = 1 << bit_index; - if val { *byte |= mask; } else { *byte &= !mask; } } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); - let mut val = 0; - for i in 0..(bit_width as usize) { if self.get_bit(i + bit_offset) { val |= 1 << i; } } - 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 fe78ae86ce..6ced319d02 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -1,9 +1,7 @@ /* automatically generated by rust-bindgen */ - #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData); @@ -41,7 +39,7 @@ impl ::std::clone::Clone for __IncompleteArrayField { } } impl ::std::marker::Copy for __IncompleteArrayField {} -/// Bizarrely enough, this should *not* get an `_address` field. +#[doc = " Bizarrely enough, this should *not* get an `_address` field."] #[repr(C)] #[derive(Debug, Default)] pub struct ZeroSizedArray { @@ -70,7 +68,7 @@ fn bindgen_test_layout_ZeroSizedArray() { ) ); } -/// And nor should this get an `_address` field. +#[doc = " And nor should this get an `_address` field."] #[repr(C)] #[derive(Debug, Default)] pub struct ContainsZeroSizedArray { @@ -99,8 +97,7 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { ) ); } -/// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted -/// either. +#[doc = " Inheriting from ZeroSizedArray shouldn\'t cause an `_address` to be inserted\n either."] #[repr(C)] #[derive(Debug, Default)] pub struct InheritsZeroSizedArray { @@ -119,7 +116,7 @@ fn bindgen_test_layout_InheritsZeroSizedArray() { concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) ); } -/// And this should not get an `_address` field either. +#[doc = " And this should not get an `_address` field either."] #[repr(C, packed)] #[derive(Debug, Default)] pub struct DynamicallySizedArray { @@ -138,7 +135,7 @@ fn bindgen_test_layout_DynamicallySizedArray() { concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); } -/// No `_address` field here either. +#[doc = " No `_address` field here either."] #[repr(C)] #[derive(Debug, Default)] pub struct ContainsDynamicallySizedArray {