Skip to content

Commit 4857d77

Browse files
Wallacolooemilio
authored andcommitted
For rust-target >= 1.30, make __BindgenUnionField::new a const fn
1 parent 5a24dbb commit 4857d77

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/codegen/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -3663,6 +3663,14 @@ mod utils {
36633663
) {
36643664
let prefix = ctx.trait_prefix();
36653665

3666+
// If the target supports `const fn`, declare eligible functions
3667+
// as `const fn` else just `fn`.
3668+
let const_fn = if ctx.options().rust_features().min_const_fn {
3669+
quote!{ const fn }
3670+
} else {
3671+
quote!{ fn }
3672+
};
3673+
36663674
// TODO(emilio): The fmt::Debug impl could be way nicer with
36673675
// std::intrinsics::type_name, but...
36683676
let union_field_decl = quote! {
@@ -3673,7 +3681,7 @@ mod utils {
36733681
let union_field_impl = quote! {
36743682
impl<T> __BindgenUnionField<T> {
36753683
#[inline]
3676-
pub fn new() -> Self {
3684+
pub #const_fn new() -> Self {
36773685
__BindgenUnionField(::#prefix::marker::PhantomData)
36783686
}
36793687

tests/expectations/tests/issue-493.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
1212
impl<T> __BindgenUnionField<T> {
1313
#[inline]
14-
pub fn new() -> Self {
14+
pub const fn new() -> Self {
1515
__BindgenUnionField(::std::marker::PhantomData)
1616
}
1717
#[inline]

0 commit comments

Comments
 (0)