Skip to content

Commit 5a24dbb

Browse files
Wallacolooemilio
authored andcommitted
FIX #1571: For rust-target >= 1.30, make __BindgenBitfieldUnit::new a const fn
1 parent 9c2cc95 commit 5a24dbb

27 files changed

+45
-28
lines changed

src/codegen/bitfield_unit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align>
99
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
1010
{
1111
#[inline]
12-
pub fn new(storage: Storage) -> Self {
12+
pub const fn new(storage: Storage) -> Self {
1313
Self {
1414
storage,
1515
align: [],

src/codegen/mod.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl CodeGenerator for Module {
410410
utils::prepend_objc_header(ctx, &mut *result);
411411
}
412412
if result.saw_bitfield_unit {
413-
utils::prepend_bitfield_unit_type(&mut *result);
413+
utils::prepend_bitfield_unit_type(ctx, &mut *result);
414414
}
415415
}
416416
};
@@ -3591,11 +3591,21 @@ mod utils {
35913591
use ir::item::{Item, ItemCanonicalPath};
35923592
use ir::ty::TypeKind;
35933593
use proc_macro2;
3594+
use std::borrow::Cow;
35943595
use std::mem;
35953596
use std::str::FromStr;
35963597

3597-
pub fn prepend_bitfield_unit_type(result: &mut Vec<proc_macro2::TokenStream>) {
3598-
let bitfield_unit_type = proc_macro2::TokenStream::from_str(include_str!("./bitfield_unit.rs")).unwrap();
3598+
pub fn prepend_bitfield_unit_type(
3599+
ctx: &BindgenContext,
3600+
result: &mut Vec<proc_macro2::TokenStream>
3601+
) {
3602+
let bitfield_unit_src = include_str!("./bitfield_unit.rs");
3603+
let bitfield_unit_src = if ctx.options().rust_features().min_const_fn {
3604+
Cow::Borrowed(bitfield_unit_src)
3605+
} else {
3606+
Cow::Owned(bitfield_unit_src.replace("const fn ", "fn "))
3607+
};
3608+
let bitfield_unit_type = proc_macro2::TokenStream::from_str(&bitfield_unit_src).unwrap();
35993609
let bitfield_unit_type = quote!(#bitfield_unit_type);
36003610

36013611
let items = vec![bitfield_unit_type];

src/features.rs

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ macro_rules! rust_target_base {
102102
=> Stable_1_27 => 1.27;
103103
/// Rust stable 1.28
104104
=> Stable_1_28 => 1.28;
105+
/// Rust stable 1.30
106+
=> Stable_1_30 => 1.30;
105107
/// Rust stable 1.33
106108
=> Stable_1_33 => 1.33;
107109
/// Nightly rust
@@ -192,6 +194,11 @@ rust_feature_def!(
192194
/// repr(transparent) ([PR](https://github.com/rust-lang/rust/pull/51562))
193195
=> repr_transparent;
194196
}
197+
Stable_1_30 {
198+
/// `const fn` support for limited cases
199+
/// ([PR](https://github.com/rust-lang/rust/pull/54835/)
200+
=> min_const_fn;
201+
}
195202
Stable_1_33 {
196203
/// repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049))
197204
=> repr_packed_n;

tests/expectations/tests/bitfield-32bit-overflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/bitfield-large.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/bitfield-method-same-name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/bitfield_align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/bitfield_align_2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/bitfield_method_mangling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/derive-bitfield-method-same-name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/derive-debug-bitfield-core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1717
}
1818
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1919
#[inline]
20-
pub fn new(storage: Storage) -> Self {
20+
pub const fn new(storage: Storage) -> Self {
2121
Self { storage, align: [] }
2222
}
2323
}

tests/expectations/tests/derive-debug-bitfield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/derive-partialeq-bitfield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/divide-by-zero-in-struct-layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/issue-1034.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/issue-739-pointer-wide-bitfield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/issue-816.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/jsval_layout_opaque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/layout_align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/layout_eth_conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/layout_mbuf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/only_bitfields.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/struct_with_bitfields.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/union_bitfield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/union_with_anon_struct_bitfield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

tests/expectations/tests/weird_bitfields.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct __BindgenBitfieldUnit<Storage, Align> {
1515
}
1616
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> {
1717
#[inline]
18-
pub fn new(storage: Storage) -> Self {
18+
pub const fn new(storage: Storage) -> Self {
1919
Self { storage, align: [] }
2020
}
2121
}

0 commit comments

Comments
 (0)