diff options
-rw-r--r-- | src/codegen/mod.rs | 10 | ||||
-rw-r--r-- | 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 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) } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index e7e5c557..dd4f6aa1 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -11,7 +11,7 @@ pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>); impl<T> __BindgenUnionField<T> { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } #[inline] |