diff options
author | Colin Wallace <colin@mooooo.ooo> | 2019-06-04 16:52:47 -0700 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-06-06 09:50:47 -0400 |
commit | 5a24dbbf28718ccb9dbcd0005746a07d0f128e81 (patch) | |
tree | bed289ceaf2db0b59abd2d8bc33100e38318f48a | |
parent | 9c2cc9520430ecbe31298c19e6b98ed5bdc0d02a (diff) |
FIX #1571: For rust-target >= 1.30, make __BindgenBitfieldUnit::new a const fn
27 files changed, 45 insertions, 28 deletions
diff --git a/src/codegen/bitfield_unit.rs b/src/codegen/bitfield_unit.rs index 5c7a09bd..caab2dc6 100755 --- a/src/codegen/bitfield_unit.rs +++ b/src/codegen/bitfield_unit.rs @@ -9,7 +9,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [], diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index c3b86983..551c0bdb 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -410,7 +410,7 @@ impl CodeGenerator for Module { utils::prepend_objc_header(ctx, &mut *result); } if result.saw_bitfield_unit { - utils::prepend_bitfield_unit_type(&mut *result); + utils::prepend_bitfield_unit_type(ctx, &mut *result); } } }; @@ -3591,11 +3591,21 @@ mod utils { use ir::item::{Item, ItemCanonicalPath}; use ir::ty::TypeKind; use proc_macro2; + use std::borrow::Cow; use std::mem; use std::str::FromStr; - pub fn prepend_bitfield_unit_type(result: &mut Vec<proc_macro2::TokenStream>) { - let bitfield_unit_type = proc_macro2::TokenStream::from_str(include_str!("./bitfield_unit.rs")).unwrap(); + pub fn prepend_bitfield_unit_type( + ctx: &BindgenContext, + result: &mut Vec<proc_macro2::TokenStream> + ) { + let bitfield_unit_src = include_str!("./bitfield_unit.rs"); + let bitfield_unit_src = if ctx.options().rust_features().min_const_fn { + Cow::Borrowed(bitfield_unit_src) + } else { + Cow::Owned(bitfield_unit_src.replace("const fn ", "fn ")) + }; + let bitfield_unit_type = proc_macro2::TokenStream::from_str(&bitfield_unit_src).unwrap(); let bitfield_unit_type = quote!(#bitfield_unit_type); let items = vec![bitfield_unit_type]; diff --git a/src/features.rs b/src/features.rs index 50759c31..05f5dc42 100644 --- a/src/features.rs +++ b/src/features.rs @@ -102,6 +102,8 @@ macro_rules! rust_target_base { => Stable_1_27 => 1.27; /// Rust stable 1.28 => Stable_1_28 => 1.28; + /// Rust stable 1.30 + => Stable_1_30 => 1.30; /// Rust stable 1.33 => Stable_1_33 => 1.33; /// Nightly rust @@ -192,6 +194,11 @@ rust_feature_def!( /// repr(transparent) ([PR](https://github.com/rust-lang/rust/pull/51562)) => repr_transparent; } + Stable_1_30 { + /// `const fn` support for limited cases + /// ([PR](https://github.com/rust-lang/rust/pull/54835/) + => min_const_fn; + } Stable_1_33 { /// repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049)) => repr_packed_n; diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs index 904a6ccc..361b0e3a 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs index 0e069b01..6597e967 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs index bbb3ac60..a105f026 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index e11751aa..7fd1f2eb 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index eb4e32b8..ee3cfea5 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index e9887ce9..9989bfe0 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index d00429cb..abe57781 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 3f07d8ff..882bb9d6 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -17,7 +17,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index b9e14337..d72dd987 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index 857e0414..c183fc0f 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } 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 a85c3930..fcfa962b 100644 --- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs index db9ce77c..4db46afe 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 6ec97f96..eef609a2 100644 --- a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index aae1cffa..213b6812 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/issue-816.rs b/tests/expectations/tests/issue-816.rs index 9fbfd9b3..e55bbb8c 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 491a6500..a2e80447 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index a6e3b8b8..c57e9742 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 3c2d5f9b..d3b22e81 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index cbb70d7a..6f95065d 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index f8f2c5de..b5db31af 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index aff22429..3f99eb02 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index 0afc9270..3bcd9ba4 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index c4512196..d8aaf221 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 7c2cc1bc..a91aae68 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> { } impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } |