From bd52c50d416179008201c0402e113a545ff831a7 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Tue, 4 Jun 2019 16:48:36 -0700 Subject: [PATCH 1/4] Remove the parameter bounds for __BindgenBitfieldUnit::new This will enable `new` to be changed to a `const fn` in a future patch: `const fn`s do not support trait bounds. --- src/codegen/bitfield_unit.rs | 9 +++++---- .../expectations/tests/bitfield-32bit-overflow.rs | 15 +++++++-------- tests/expectations/tests/bitfield-large.rs | 15 +++++++-------- .../tests/bitfield-method-same-name.rs | 15 +++++++-------- tests/expectations/tests/bitfield_align.rs | 15 +++++++-------- tests/expectations/tests/bitfield_align_2.rs | 15 +++++++-------- .../tests/bitfield_method_mangling.rs | 15 +++++++-------- .../tests/derive-bitfield-method-same-name.rs | 15 +++++++-------- .../tests/derive-debug-bitfield-core.rs | 15 +++++++-------- tests/expectations/tests/derive-debug-bitfield.rs | 15 +++++++-------- .../tests/derive-partialeq-bitfield.rs | 15 +++++++-------- .../tests/divide-by-zero-in-struct-layout.rs | 15 +++++++-------- tests/expectations/tests/issue-1034.rs | 15 +++++++-------- .../issue-1076-unnamed-bitfield-alignment.rs | 15 +++++++-------- .../tests/issue-739-pointer-wide-bitfield.rs | 15 +++++++-------- tests/expectations/tests/issue-816.rs | 15 +++++++-------- tests/expectations/tests/jsval_layout_opaque.rs | 15 +++++++-------- .../expectations/tests/jsval_layout_opaque_1_0.rs | 15 +++++++-------- tests/expectations/tests/layout_align.rs | 15 +++++++-------- tests/expectations/tests/layout_eth_conf.rs | 15 +++++++-------- tests/expectations/tests/layout_eth_conf_1_0.rs | 15 +++++++-------- tests/expectations/tests/layout_mbuf.rs | 15 +++++++-------- tests/expectations/tests/layout_mbuf_1_0.rs | 15 +++++++-------- tests/expectations/tests/only_bitfields.rs | 15 +++++++-------- tests/expectations/tests/struct_with_bitfields.rs | 15 +++++++-------- tests/expectations/tests/union_bitfield.rs | 15 +++++++-------- tests/expectations/tests/union_bitfield_1_0.rs | 15 +++++++-------- .../tests/union_with_anon_struct_bitfield.rs | 15 +++++++-------- .../tests/union_with_anon_struct_bitfield_1_0.rs | 15 +++++++-------- tests/expectations/tests/weird_bitfields.rs | 15 +++++++-------- 30 files changed, 208 insertions(+), 236 deletions(-) diff --git a/src/codegen/bitfield_unit.rs b/src/codegen/bitfield_unit.rs index 7f263fd12f..5c7a09bd6b 100755 --- a/src/codegen/bitfield_unit.rs +++ b/src/codegen/bitfield_unit.rs @@ -1,16 +1,12 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, { storage: Storage, align: [Align; 0], } impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, { #[inline] pub fn new(storage: Storage) -> Self { @@ -19,7 +15,12 @@ where align: [], } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs index 9cb1f15244..904a6ccc8d 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs index 1791cd32ca..0e069b0130 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs index 46c4744ea9..bbb3ac60d1 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 35e9479bab..e11751aab5 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 6f93397fc6..eb4e32b848 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index 8ebb778d69..e9887ce95f 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 70ee2973a5..d00429cb62 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 613e00f385..3f07d8ffc0 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -11,21 +11,20 @@ extern crate core; #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 88a41d7890..b9e14337c7 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index f4d916621b..857e0414c0 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); 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 1cdd1e09aa..a85c3930d4 100644 --- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs index cd0c72179b..db9ce77c47 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 7a4b77fbad..6ec97f96b5 100644 --- a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index ca56ccceb0..aae1cffa34 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/issue-816.rs b/tests/expectations/tests/issue-816.rs index b5e30fbedd..9fbfd9b399 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index aa0420aa0b..491a6500ce 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 7bd58819fc..b09d129cf2 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index e655b9dc8f..a6e3b8b8cd 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 5582c7ded3..3c2d5f9b44 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index b8c20f3d4c..0234bbd486 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 6ed1d13083..cbb70d7a98 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index a1ec285ee9..b1fb2b9d59 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index 9d925217a9..f8f2c5de71 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 3145945243..aff22429dd 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index d6f52ef5d0..0afc927084 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/tests/expectations/tests/union_bitfield_1_0.rs index abc7c4b056..c875538114 100644 --- a/tests/expectations/tests/union_bitfield_1_0.rs +++ b/tests/expectations/tests/union_bitfield_1_0.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index f97f122cf0..c451219659 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); 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 83ee80eb37..2895a391ec 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 @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 32220edb2f..7c2cc1bcab 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -9,21 +9,20 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +pub struct __BindgenBitfieldUnit { storage: Storage, align: [Align; 0], } -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { Self { storage, align: [] } } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ #[inline] pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); From fe596b51d1ea40180153cbbf9306d762241b784f Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Tue, 4 Jun 2019 16:52:47 -0700 Subject: [PATCH 2/4] FIX #1571: For rust-target >= 1.30, make __BindgenBitfieldUnit::new a const fn --- src/codegen/bitfield_unit.rs | 2 +- src/codegen/mod.rs | 16 +++++++++++++--- src/features.rs | 7 +++++++ .../tests/bitfield-32bit-overflow.rs | 2 +- tests/expectations/tests/bitfield-large.rs | 2 +- .../tests/bitfield-method-same-name.rs | 2 +- tests/expectations/tests/bitfield_align.rs | 2 +- tests/expectations/tests/bitfield_align_2.rs | 2 +- .../tests/bitfield_method_mangling.rs | 2 +- .../tests/derive-bitfield-method-same-name.rs | 2 +- .../tests/derive-debug-bitfield-core.rs | 2 +- .../expectations/tests/derive-debug-bitfield.rs | 2 +- .../tests/derive-partialeq-bitfield.rs | 2 +- .../tests/divide-by-zero-in-struct-layout.rs | 2 +- tests/expectations/tests/issue-1034.rs | 2 +- .../issue-1076-unnamed-bitfield-alignment.rs | 2 +- .../tests/issue-739-pointer-wide-bitfield.rs | 2 +- tests/expectations/tests/issue-816.rs | 2 +- tests/expectations/tests/jsval_layout_opaque.rs | 2 +- tests/expectations/tests/layout_align.rs | 2 +- tests/expectations/tests/layout_eth_conf.rs | 2 +- tests/expectations/tests/layout_mbuf.rs | 2 +- tests/expectations/tests/only_bitfields.rs | 2 +- .../expectations/tests/struct_with_bitfields.rs | 2 +- tests/expectations/tests/union_bitfield.rs | 2 +- .../tests/union_with_anon_struct_bitfield.rs | 2 +- tests/expectations/tests/weird_bitfields.rs | 2 +- 27 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/codegen/bitfield_unit.rs b/src/codegen/bitfield_unit.rs index 5c7a09bd6b..caab2dc69a 100755 --- a/src/codegen/bitfield_unit.rs +++ b/src/codegen/bitfield_unit.rs @@ -9,7 +9,7 @@ pub struct __BindgenBitfieldUnit impl __BindgenBitfieldUnit { #[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 c3b8698319..551c0bdb91 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) { - 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 + ) { + 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 50759c3189..05f5dc422e 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 904a6ccc8d..361b0e3ae0 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 0e069b0130..6597e9672c 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 bbb3ac60d1..a105f026b5 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 { } impl __BindgenBitfieldUnit { #[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 e11751aab5..7fd1f2eb2a 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 eb4e32b848..ee3cfea5e5 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 e9887ce95f..9989bfe09e 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 d00429cb62..abe57781a5 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 { } impl __BindgenBitfieldUnit { #[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 3f07d8ffc0..882bb9d632 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 { } impl __BindgenBitfieldUnit { #[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 b9e14337c7..d72dd98772 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 857e0414c0..c183fc0f84 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 a85c3930d4..fcfa962bdc 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 { } impl __BindgenBitfieldUnit { #[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 db9ce77c47..4db46afe0d 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 6ec97f96b5..eef609a28d 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 { } impl __BindgenBitfieldUnit { #[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 aae1cffa34..213b6812da 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 { } impl __BindgenBitfieldUnit { #[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 9fbfd9b399..e55bbb8ca0 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 491a6500ce..a2e8044748 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 a6e3b8b8cd..c57e97423a 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 3c2d5f9b44..d3b22e8122 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 cbb70d7a98..6f95065dd9 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 f8f2c5de71..b5db31affd 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 aff22429dd..3f99eb0268 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 0afc927084..3bcd9ba461 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[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 c451219659..d8aaf22191 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 { } impl __BindgenBitfieldUnit { #[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 7c2cc1bcab..a91aae684f 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit { } impl __BindgenBitfieldUnit { #[inline] - pub fn new(storage: Storage) -> Self { + pub const fn new(storage: Storage) -> Self { Self { storage, align: [] } } } From 5ca9a2171fa88a81dc8ce8ce13a0843c25015889 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Tue, 4 Jun 2019 16:35:25 -0700 Subject: [PATCH 3/4] For rust-target >= 1.30, make __BindgenUnionField::new a const fn --- src/codegen/mod.rs | 10 +++++++++- tests/expectations/tests/issue-493.rs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 551c0bdb91..693215a5e4 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3663,6 +3663,14 @@ mod utils { ) { let prefix = ctx.trait_prefix(); + // If the target supports `const fn`, declare eligible functions + // as `const fn` else just `fn`. + let const_fn = if ctx.options().rust_features().min_const_fn { + quote!{ const fn } + } else { + quote!{ fn } + }; + // TODO(emilio): The fmt::Debug impl could be way nicer with // std::intrinsics::type_name, but... let union_field_decl = quote! { @@ -3673,7 +3681,7 @@ mod utils { let union_field_impl = quote! { impl __BindgenUnionField { #[inline] - pub fn new() -> Self { + pub #const_fn new() -> Self { __BindgenUnionField(::#prefix::marker::PhantomData) } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index e7e5c5579c..dd4f6aa188 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -11,7 +11,7 @@ pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } #[inline] From 05ba82dc261fad0cacd1927b32d98c1691a13a7c Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Tue, 4 Jun 2019 16:35:56 -0700 Subject: [PATCH 4/4] For rust-target >= 1.30, make __IncompleteArrayField::new a const fn --- src/codegen/mod.rs | 10 +++++++++- tests/expectations/tests/class.rs | 2 +- .../tests/derive-hash-struct-with-incomplete-array.rs | 2 +- tests/expectations/tests/issue-643-inner-struct.rs | 2 +- tests/expectations/tests/layout_align.rs | 2 +- tests/expectations/tests/layout_large_align_field.rs | 2 +- tests/expectations/tests/zero-size-array-align.rs | 2 +- tests/expectations/tests/zero-sized-array.rs | 2 +- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 693215a5e4..ceb2f5b86a 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3770,6 +3770,14 @@ mod utils { ) { let prefix = ctx.trait_prefix(); + // If the target supports `const fn`, declare eligible functions + // as `const fn` else just `fn`. + let const_fn = if ctx.options().rust_features().min_const_fn { + quote!{ const fn } + } else { + quote!{ fn } + }; + let incomplete_array_decl = quote! { #[repr(C)] #[derive(Default)] @@ -3780,7 +3788,7 @@ mod utils { let incomplete_array_impl = quote! { impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub #const_fn new() -> Self { __IncompleteArrayField(::#prefix::marker::PhantomData, []) } diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index f52f0f8580..be1380417a 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -12,7 +12,7 @@ pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 8e87432f74..a38fd27db4 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -12,7 +12,7 @@ pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index a9696a6d5f..e9384c078a 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -12,7 +12,7 @@ pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index c57e97423a..ea41b08fe5 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -93,7 +93,7 @@ where pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 4c10223c6c..a02eff58ac 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -12,7 +12,7 @@ pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 9c60d14e82..1debdaea47 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -12,7 +12,7 @@ pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index e002251dbb..a1ad22d665 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -12,7 +12,7 @@ pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline]