Skip to content

Commit

Permalink
FIX rust-lang#1571: For rust-target >= 1.30, make __BindgenBitfieldUn…
Browse files Browse the repository at this point in the history
…it::new a const fn
  • Loading branch information
Wallacoloo committed Jun 5, 2019
1 parent bd52c50 commit fe596b5
Show file tree
Hide file tree
Showing 27 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/codegen/bitfield_unit.rs
Expand Up @@ -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: [],
Expand Down
16 changes: 13 additions & 3 deletions src/codegen/mod.rs
Expand Up @@ -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);
}
}
};
Expand Down Expand Up @@ -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];
Expand Down
7 changes: 7 additions & 0 deletions src/features.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/bitfield-32bit-overflow.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/bitfield-large.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/bitfield-method-same-name.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/bitfield_align.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/bitfield_align_2.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/bitfield_method_mangling.rs
Expand Up @@ -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: [] }
}
}
Expand Down
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/derive-debug-bitfield-core.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/derive-debug-bitfield.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/derive-partialeq-bitfield.rs
Expand Up @@ -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: [] }
}
}
Expand Down
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-1034.rs
Expand Up @@ -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: [] }
}
}
Expand Down
Expand Up @@ -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: [] }
}
}
Expand Down
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-816.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/jsval_layout_opaque.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout_align.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout_eth_conf.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout_mbuf.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/only_bitfields.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/struct_with_bitfields.rs
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/union_bitfield.rs
Expand Up @@ -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: [] }
}
}
Expand Down
Expand Up @@ -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: [] }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/weird_bitfields.rs
Expand Up @@ -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: [] }
}
}
Expand Down

0 comments on commit fe596b5

Please sign in to comment.