Skip to content

Commit

Permalink
For rust-target >= 1.30, make __IncompleteArrayField::new a const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Wallacoloo authored and emilio committed Jun 6, 2019
1 parent 4857d77 commit d55cce5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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, [])
}

Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/issue-643-inner-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/layout_large_align_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/zero-size-array-align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/zero-sized-array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d55cce5

Please sign in to comment.