Skip to content

Commit d55cce5

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

8 files changed

+16
-8
lines changed

src/codegen/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -3770,6 +3770,14 @@ mod utils {
37703770
) {
37713771
let prefix = ctx.trait_prefix();
37723772

3773+
// If the target supports `const fn`, declare eligible functions
3774+
// as `const fn` else just `fn`.
3775+
let const_fn = if ctx.options().rust_features().min_const_fn {
3776+
quote!{ const fn }
3777+
} else {
3778+
quote!{ fn }
3779+
};
3780+
37733781
let incomplete_array_decl = quote! {
37743782
#[repr(C)]
37753783
#[derive(Default)]
@@ -3780,7 +3788,7 @@ mod utils {
37803788
let incomplete_array_impl = quote! {
37813789
impl<T> __IncompleteArrayField<T> {
37823790
#[inline]
3783-
pub fn new() -> Self {
3791+
pub #const_fn new() -> Self {
37843792
__IncompleteArrayField(::#prefix::marker::PhantomData, [])
37853793
}
37863794

tests/expectations/tests/class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
1313
impl<T> __IncompleteArrayField<T> {
1414
#[inline]
15-
pub fn new() -> Self {
15+
pub const fn new() -> Self {
1616
__IncompleteArrayField(::std::marker::PhantomData, [])
1717
}
1818
#[inline]

tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
1313
impl<T> __IncompleteArrayField<T> {
1414
#[inline]
15-
pub fn new() -> Self {
15+
pub const fn new() -> Self {
1616
__IncompleteArrayField(::std::marker::PhantomData, [])
1717
}
1818
#[inline]

tests/expectations/tests/issue-643-inner-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
1313
impl<T> __IncompleteArrayField<T> {
1414
#[inline]
15-
pub fn new() -> Self {
15+
pub const fn new() -> Self {
1616
__IncompleteArrayField(::std::marker::PhantomData, [])
1717
}
1818
#[inline]

tests/expectations/tests/layout_align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
9494
impl<T> __IncompleteArrayField<T> {
9595
#[inline]
96-
pub fn new() -> Self {
96+
pub const fn new() -> Self {
9797
__IncompleteArrayField(::std::marker::PhantomData, [])
9898
}
9999
#[inline]

tests/expectations/tests/layout_large_align_field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
1313
impl<T> __IncompleteArrayField<T> {
1414
#[inline]
15-
pub fn new() -> Self {
15+
pub const fn new() -> Self {
1616
__IncompleteArrayField(::std::marker::PhantomData, [])
1717
}
1818
#[inline]

tests/expectations/tests/zero-size-array-align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
1313
impl<T> __IncompleteArrayField<T> {
1414
#[inline]
15-
pub fn new() -> Self {
15+
pub const fn new() -> Self {
1616
__IncompleteArrayField(::std::marker::PhantomData, [])
1717
}
1818
#[inline]

tests/expectations/tests/zero-sized-array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
1313
impl<T> __IncompleteArrayField<T> {
1414
#[inline]
15-
pub fn new() -> Self {
15+
pub const fn new() -> Self {
1616
__IncompleteArrayField(::std::marker::PhantomData, [])
1717
}
1818
#[inline]

0 commit comments

Comments
 (0)