|
@@ -1,7 +1,6 @@
|
|
|
use crate::parser::docs;
|
|
|
use crate::*;
|
|
|
use syn::parse::{Error as ParseError, Result as ParseResult};
|
|
|
-use syn::parse_quote;
|
|
|
use syn::punctuated::Punctuated;
|
|
|
use syn::spanned::Spanned;
|
|
|
use syn::token::Comma;
|
|
@@ -438,7 +437,7 @@ fn parse_program_ty(path: &syn::Path) -> ParseResult<ProgramTy> {
|
|
|
Ok(ProgramTy { account_type_path })
|
|
|
}
|
|
|
|
|
|
-// Extract the type path '_' from Box<Account<'info, _>> or Account<'info, _>
|
|
|
+// Extract the type path T from Box<[AccountType]<'info, T>> or [AccountType]<'info, T>
|
|
|
fn parse_account(path: &syn::Path) -> ParseResult<syn::TypePath> {
|
|
|
let segment = &path.segments[0];
|
|
|
match segment.ident.to_string().as_str() {
|
|
@@ -447,7 +446,7 @@ fn parse_account(path: &syn::Path) -> ParseResult<syn::TypePath> {
|
|
|
if args.args.len() != 1 {
|
|
|
return Err(ParseError::new(
|
|
|
args.args.span(),
|
|
|
- "Expected a single `Account<'info, _>` argument",
|
|
|
+ "Expected a single argument: [AccountType]<'info, T>",
|
|
|
));
|
|
|
}
|
|
|
match &args.args[0] {
|
|
@@ -457,7 +456,7 @@ fn parse_account(path: &syn::Path) -> ParseResult<syn::TypePath> {
|
|
|
_ => {
|
|
|
Err(ParseError::new(
|
|
|
args.args[1].span(),
|
|
|
- "Expected a path containing `Account<'info, _>`",
|
|
|
+ "Expected a path containing: [AccountType]<'info, T>",
|
|
|
))
|
|
|
}
|
|
|
}
|
|
@@ -465,16 +464,16 @@ fn parse_account(path: &syn::Path) -> ParseResult<syn::TypePath> {
|
|
|
_ => {
|
|
|
Err(ParseError::new(
|
|
|
segment.arguments.span(),
|
|
|
- "expected angle brackets with a type",
|
|
|
+ "Expected angle brackets with a type: Box<[AccountType]<'info, T>",
|
|
|
))
|
|
|
}
|
|
|
},
|
|
|
- "Account" => match &segment.arguments {
|
|
|
+ _ => match &segment.arguments {
|
|
|
syn::PathArguments::AngleBracketed(args) => {
|
|
|
if args.args.len() != 2 {
|
|
|
return Err(ParseError::new(
|
|
|
args.args.span(),
|
|
|
- "Expected only two arguments, a lifetime and a type",
|
|
|
+ "Expected only two arguments, a lifetime and a type: [AccountType]<'info, T>",
|
|
|
));
|
|
|
}
|
|
|
match (&args.args[0], &args.args[1]) {
|
|
@@ -487,7 +486,7 @@ fn parse_account(path: &syn::Path) -> ParseResult<syn::TypePath> {
|
|
|
_ => {
|
|
|
Err(ParseError::new(
|
|
|
args.args.span(),
|
|
|
- "Expected the two arguments to be a lifetime and a type",
|
|
|
+ "Expected the two arguments to be a lifetime and a type: [AccountType]<'info, T>",
|
|
|
))
|
|
|
}
|
|
|
}
|
|
@@ -495,16 +494,10 @@ fn parse_account(path: &syn::Path) -> ParseResult<syn::TypePath> {
|
|
|
_ => {
|
|
|
Err(ParseError::new(
|
|
|
segment.arguments.span(),
|
|
|
- "expected angle brackets with a type",
|
|
|
+ "Expected angle brackets with a type: [AccountType]<'info, T>",
|
|
|
))
|
|
|
}
|
|
|
},
|
|
|
- _ => {
|
|
|
- Err(ParseError::new(
|
|
|
- segment.ident.span(),
|
|
|
- "unexpected ident, expected 'Box<Account>' or 'Account'",
|
|
|
- ))
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -569,44 +562,30 @@ fn parse_sysvar(path: &syn::Path) -> ParseResult<SysvarTy> {
|
|
|
|
|
|
#[test]
|
|
|
fn test_parse_account() {
|
|
|
- let expected_ty_path: syn::TypePath = parse_quote!(u32);
|
|
|
- let path = parse_quote! { Box<Account<'info, u32>> };
|
|
|
+ let expected_ty_path: syn::TypePath = syn::parse_quote!(u32);
|
|
|
+ let path = syn::parse_quote! { Box<Account<'info, u32>> };
|
|
|
let ty = parse_account(&path).unwrap();
|
|
|
assert_eq!(ty, expected_ty_path);
|
|
|
|
|
|
- let path = parse_quote! { Account<'info, u32> };
|
|
|
+ let path = syn::parse_quote! { Account<'info, u32> };
|
|
|
let ty = parse_account(&path).unwrap();
|
|
|
assert_eq!(ty, expected_ty_path);
|
|
|
|
|
|
- let path = parse_quote! { OtherType<'info, u32> };
|
|
|
+ let path = syn::parse_quote! { Box<Account<'info, u32, u64>> };
|
|
|
let err = parse_account(&path).unwrap_err();
|
|
|
assert_eq!(
|
|
|
err.to_string(),
|
|
|
- "unexpected ident, expected 'Box<Account>' or 'Account'"
|
|
|
+ "Expected only two arguments, a lifetime and a type: [AccountType]<'info, T>"
|
|
|
);
|
|
|
|
|
|
- let path = parse_quote! { Box<Account<'info, u32, u64>> };
|
|
|
+ let path = syn::parse_quote! { Box<Account<'info>> };
|
|
|
let err = parse_account(&path).unwrap_err();
|
|
|
assert_eq!(
|
|
|
err.to_string(),
|
|
|
- "Expected only two arguments, a lifetime and a type"
|
|
|
+ "Expected only two arguments, a lifetime and a type: [AccountType]<'info, T>"
|
|
|
);
|
|
|
|
|
|
- let path = parse_quote! { Box<Account<'info>> };
|
|
|
+ let path = syn::parse_quote! { Box<Account> };
|
|
|
let err = parse_account(&path).unwrap_err();
|
|
|
- assert_eq!(
|
|
|
- err.to_string(),
|
|
|
- "Expected only two arguments, a lifetime and a type"
|
|
|
- );
|
|
|
-
|
|
|
- let path = parse_quote! { Box<Account> };
|
|
|
- let err = parse_account(&path).unwrap_err();
|
|
|
- assert_eq!(err.to_string(), "expected angle brackets with a type");
|
|
|
-
|
|
|
- let path = parse_quote! { Box<OtherType<'info, u32>> };
|
|
|
- let err = parse_account(&path).unwrap_err();
|
|
|
- assert_eq!(
|
|
|
- err.to_string(),
|
|
|
- "unexpected ident, expected 'Box<Account>' or 'Account'"
|
|
|
- );
|
|
|
+ assert_eq!(err.to_string(), "Expected angle brackets with a type: [AccountType]<'info, T>");
|
|
|
}
|