summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Wallace <colin@mooooo.ooo>2019-06-04 16:35:25 -0700
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-06-06 09:50:47 -0400
commit4857d77a879d5b8330b3d6c2716e4f449d494bc5 (patch)
tree4b5b595058a0b200f846a946eb000215badacf23 /src
parent5a24dbbf28718ccb9dbcd0005746a07d0f128e81 (diff)
For rust-target >= 1.30, make __BindgenUnionField::new a const fn
Diffstat (limited to 'src')
-rw-r--r--src/codegen/mod.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 551c0bdb..693215a5 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<T> __BindgenUnionField<T> {
#[inline]
- pub fn new() -> Self {
+ pub #const_fn new() -> Self {
__BindgenUnionField(::#prefix::marker::PhantomData)
}