Skip to content

Commit e6c666b

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

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lang/syn/src/idl/program.rs

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

0 commit comments

Comments
 (0)