2

I'm trying This example by anchor to initialize large accounts and using zero_copy on them.

https://github.com/coral-xyz/anchor/blob/master/tests/zero-copy/programs/zero-copy/src/lib.rs#L156-L165

I'm getting this error on this

the trait bound `[Event; 25000]: Zeroable` is not satisfied
   --> src/lib.rs:158:17
    |
158 |     pub events: [Event; 25000],
    |                 ^^^^^^^^^^^^^^ the trait `Zeroable` is not implemented for `[Event; 25000]`
    |
    = help: the following other types implement trait `Zeroable`:
              *const [T]
              *mut [T]
              [T; 0]
              [T; 1024]
              [T; 10]
              [T; 11]
              [T; 128]
              [T; 12]
            and 36 others
note: required by a bound in `_::{closure#0}::check::assert_impl`
   --> src/lib.rs:155:1
    |
155 |   #[account(zero_copy)]
    |   ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl`
156 | / #[repr(C)]
157 | | pub struct EventQ {
158 | |     pub events: [Event; 25000],
159 | | }
    | |_- required by a bound in this
    = note: this error originates in the derive macro `::bytemuck::Zeroable` 
 
error[E0277]: the trait bound `[Event; 25000]: Pod` is not satisfied
   --> src/lib.rs:158:17
    |
158 |     pub events: [Event; 25000],
    |                 ^^^^^^^^^^^^^^ the trait `Pod` is not implemented for `[Event; 25000]`
    |
    = help: the following other types implement trait `Pod`:
              [T; 0]
              [T; 1024]
              [T; 10]
              [T; 11]
              [T; 128]
              [T; 12]
              [T; 13]
              [T; 14]
            and 34 others
note: required by a bound in `_::{closure#0}::check::assert_impl`
   --> src/lib.rs:155:1
    |
155 | #[account(zero_copy)]
    | ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_impl`
    = note: this error originates in the derive macro `::bytemuck::Pod` 

2 Answers 2

3

I guess the example is out of date in Anchor 27 there was a breaking change for zero copy:

"lang: account(zero_copy) and zero_copy attributes now derive the bytemuck::Pod and bytemuck::Zeroable traits instead of using unsafe impl (#2330). This imposes useful restrictions on the type, like not having padding bytes and all fields being Pod themselves. See bytemuck::Pod for details. This change requires adding bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]} to your cargo.toml. Legacy applications can still use #[account(zero_copy(unsafe))] and #[zero_copy(unsafe)] for the old behavior."

https://github.com/coral-xyz/anchor/blob/master/CHANGELOG.md

So you should be able to still use the example using

#[account(zero_copy(unsafe))] 

Here is some newer examples: https://github.com/solana-developers/anchor-zero-copy-example

2

This is fixed now , I assume this was the commit that fixed it : https://github.com/coral-xyz/anchor/commit/ed2769ef2849007fd93ee6bd08e0e07dd69bf40c#comments, with anchor moving to safe impl of bytemuck pod and zero able traits, the const generic feature missing prolly cause the above build error. since the impl of the trait for array of N length is behind a feature flag. source : https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html#features

Some impls are feature gated due to the MSRV policy:

MaybeUninit was not available in 1.34.0, but is available under the zeroable_maybe_uninit feature flag. Atomic* types require Rust 1.60.0 or later to work on certain platforms, but is available under the zeroable_atomics feature flag. [T; N] for arbitrary N requires the min_const_generics feature flag.

impl<T, const N: usize> Zeroable for [T; N] where T: Zeroable, Available on crate feature min_const_generics only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.