Skip to content

Commit 266da38

Browse files
committed
fix: Use field span in IDL safety check errors
Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>
1 parent e8acb46 commit 266da38

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lang/syn/src/idl/program.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
2020
Ok(tokens) => tokens,
2121
Err(e) => {
2222
// If we can't perform safety checks, emit a compile error
23-
return syn::Error::new(proc_macro2::Span::call_site(), e.to_string())
23+
// Use the span of the first instruction if available, otherwise use the program module span
24+
let error_span = program
25+
.ixs
26+
.first()
27+
.map(|ix| ix.raw_method.span())
28+
.unwrap_or_else(|| program.program_mod.span());
29+
return syn::Error::new(error_span, e.to_string())
2430
.to_compile_error();
2531
}
2632
};

0 commit comments

Comments
 (0)