Skip to content

Commit 26cd733

Browse files
committed
refactor: Restore quote_spanned! in accounts.rs for better error messages
Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>
1 parent e805d2a commit 26cd733

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lang/syn/src/codegen/program/accounts.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use crate::Program;
22
use heck::SnakeCase;
3-
use quote::quote;
3+
use quote::{quote, quote_spanned};
4+
use syn::spanned::Spanned;
45

56
pub fn generate(program: &Program) -> proc_macro2::TokenStream {
67
let mut accounts = std::collections::HashMap::new();
8+
let mut ix_spans = std::collections::HashMap::new();
79

810
// Go through instruction accounts.
911
for ix in &program.ixs {
@@ -13,6 +15,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
1315
"__client_accounts_{}",
1416
anchor_ident.to_string().to_snake_case()
1517
);
18+
ix_spans.insert(macro_name.clone(), ix.raw_method.span());
1619
accounts.insert(macro_name, ix.cfgs.as_slice());
1720
}
1821

@@ -21,7 +24,11 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
2124
.iter()
2225
.map(|(macro_name_str, cfgs)| {
2326
let macro_name: proc_macro2::TokenStream = macro_name_str.parse().unwrap();
24-
quote! {
27+
let ix_span = ix_spans
28+
.get(macro_name_str)
29+
.copied()
30+
.unwrap_or_else(proc_macro2::Span::call_site);
31+
quote_spanned! { ix_span =>
2532
#(#cfgs)*
2633
pub use crate::#macro_name::*;
2734
}

0 commit comments

Comments
 (0)