summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/mod.rs10
-rw-r--r--tests/expectations/tests/class.rs2
-rw-r--r--tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs2
-rw-r--r--tests/expectations/tests/issue-643-inner-struct.rs2
-rw-r--r--tests/expectations/tests/layout_align.rs2
-rw-r--r--tests/expectations/tests/layout_large_align_field.rs2
-rw-r--r--tests/expectations/tests/zero-size-array-align.rs2
-rw-r--r--tests/expectations/tests/zero-sized-array.rs2
8 files changed, 16 insertions, 8 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 693215a5..ceb2f5b8 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3770,6 +3770,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 }
+ };
+
let incomplete_array_decl = quote! {
#[repr(C)]
#[derive(Default)]
@@ -3780,7 +3788,7 @@ mod utils {
let incomplete_array_impl = quote! {
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub #const_fn new() -> Self {
__IncompleteArrayField(::#prefix::marker::PhantomData, [])
}
diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs
index f52f0f85..be138041 100644
--- a/tests/expectations/tests/class.rs
+++ b/tests/expectations/tests/class.rs
@@ -12,7 +12,7 @@
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs
index 8e87432f..a38fd27d 100644
--- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs
+++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs
@@ -12,7 +12,7 @@
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs
index a9696a6d..e9384c07 100644
--- a/tests/expectations/tests/issue-643-inner-struct.rs
+++ b/tests/expectations/tests/issue-643-inner-struct.rs
@@ -12,7 +12,7 @@
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs
index c57e9742..ea41b08f 100644
--- a/tests/expectations/tests/layout_align.rs
+++ b/tests/expectations/tests/layout_align.rs
@@ -93,7 +93,7 @@ where
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs
index 4c10223c..a02eff58 100644
--- a/tests/expectations/tests/layout_large_align_field.rs
+++ b/tests/expectations/tests/layout_large_align_field.rs
@@ -12,7 +12,7 @@
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs
index 9c60d14e..1debdaea 100644
--- a/tests/expectations/tests/zero-size-array-align.rs
+++ b/tests/expectations/tests/zero-size-array-align.rs
@@ -12,7 +12,7 @@
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs
index e002251d..a1ad22d6 100644
--- a/tests/expectations/tests/zero-sized-array.rs
+++ b/tests/expectations/tests/zero-sized-array.rs
@@ -12,7 +12,7 @@
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
- pub fn new() -> Self {
+ pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]