Browse Source

lang: Allow seeds to have a trailing comma (#777)

Alan O'Donnell 4 năm trước cách đây
mục cha
commit
42ed126163

+ 6 - 1
lang/syn/src/codegen/accounts/constraints.rs

@@ -281,7 +281,12 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
     let seeds_with_nonce = match &c.seeds {
         None => quote! {},
         Some(c) => {
-            let s = &c.seeds;
+            let s = &mut c.seeds.clone();
+            // If the seeds came with a trailing comma, we need to chop it off
+            // before we interpolate them below.
+            if let Some(pair) = s.pop() {
+                s.push_value(pair.into_value());
+            }
             let inner = match c.bump.as_ref() {
                 // Bump target not given. Use the canonical bump.
                 None => {

+ 1 - 1
tests/misc/programs/misc/src/context.rs

@@ -18,7 +18,7 @@ pub struct TestTokenSeedsInit<'info> {
     pub mint: Account<'info, Mint>,
     #[account(
         init,
-        seeds = [b"my-token-seed".as_ref()],
+        seeds = [b"my-token-seed".as_ref(),],
         bump = token_bump,
         payer = authority,
         token::mint = mint,