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 /src/codegen/mod.rs | |
parent | 9c2cc9520430ecbe31298c19e6b98ed5bdc0d02a (diff) |
FIX #1571: For rust-target >= 1.30, make __BindgenBitfieldUnit::new a const fn
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 16 |
1 files changed, 13 insertions, 3 deletions
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]; |